MCPcopy Index your code
hub / github.com/unicity-sphere/sphere-sdk-connect-example

github.com/unicity-sphere/sphere-sdk-connect-example @main sqlite

repository ↗ · DeepWiki ↗
104 symbols 187 edges 31 files 1 documented · 1%
README

Sphere Connect Example

Demonstration project showing how to integrate the Sphere Connect protocol into browser and Node.js applications.

What is Sphere Connect?

Sphere Connect is a typed RPC protocol that allows web dApps to communicate with a Sphere wallet — reading balances, sending tokens, signing messages — without exposing private keys.

dApp (ConnectClient)  ←→  Transport  ←→  Wallet (ConnectHost)

Project Structure

sphere-sdk-connect-example/
├── browser/     # React dApp example (Vite + Tailwind)
└── nodejs/      # Node.js CLI client + mock wallet server

Quick Start

Browser dApp

cd browser
npm install
npm run dev        # http://localhost:5174

Requires a Sphere wallet at http://localhost:5173 (or Sphere extension installed).

Node.js CLI

cd nodejs
npm install
npm run server     # Terminal 1: mock wallet (ws://localhost:8765)
npm run client     # Terminal 2: CLI client

Browser Example Features

All queries, intents, and events are demonstrated:

Queries (read-only): sphere_getIdentity · sphere_getBalance · sphere_getAssets · sphere_getFiatBalance · sphere_getTokens · sphere_getHistory · sphere_resolve

Intents (require wallet approval): send · mint · dm · payment_request · receive · sign_message

Events (real-time push): auto-pushed wallet:locked · identity:changed · subscribable transfer:incoming · transfer:confirmed · transfer:failed · and more

3-Priority Transport Selection

import { isInIframe, hasExtension } from './lib/detection';

if (isInIframe()) {
  // P1: dApp embedded inside Sphere as iframe
  transport = PostMessageTransport.forClient();
} else if (hasExtension()) {
  // P2: Sphere browser extension installed
  transport = ExtensionTransport.forClient();
} else {
  // P3: open Sphere as popup window
  transport = PostMessageTransport.forClient({ target: popup, targetOrigin: WALLET_URL });
}

Auto-Connect on Page Load

// Silent check — no popup if not approved
const client = new ConnectClient({ transport, dapp, silent: true });
try {
  await client.connect();   // instant if already approved
} catch {
  // Show Connect button
}

Dependencies

Both subprojects pin a published sphere-sdk version:

"@unicitylabs/sphere-sdk": "0.10.2"

Documentation

License

MIT

Extension points exported contracts — how you extend this code

ConnectButtonProps (Interface)
(no doc)
browser/src/components/ConnectButton.tsx
PageShellProps (Interface)
(no doc)
browser/src/components/layout/PageShell.tsx
NavItem (Interface)
(no doc)
browser/src/components/layout/PageShell.tsx
WalletHeaderProps (Interface)
(no doc)
browser/src/components/layout/WalletHeader.tsx
Props (Interface)
(no doc)
browser/src/components/queries/AssetsPanel.tsx

Core symbols most depended-on inside this repo

makeClient
called by 7
browser/src/hooks/useWalletConnect.ts
formatAmount
called by 6
browser/src/lib/format.ts
truncate
called by 5
browser/src/lib/format.ts
safeParseAmount
called by 4
browser/src/lib/format.ts
isInIframe
called by 4
browser/src/lib/detection.ts
hasExtension
called by 4
browser/src/lib/detection.ts
parseAmount
called by 3
browser/src/lib/format.ts
showPrompt
called by 3
nodejs/src/index.ts

Shape

Function 68
Interface 36

Languages

TypeScript100%

Modules by API surface

browser/src/hooks/useWalletConnect.ts9 symbols
browser/src/components/queries/HistoryPanel.tsx9 symbols
browser/src/lib/format.ts8 symbols
browser/src/lib/types.ts7 symbols
browser/src/components/ui/CoinSelect.tsx5 symbols
browser/src/components/queries/IdentityPanel.tsx4 symbols
browser/src/components/queries/BalancePanel.tsx4 symbols
browser/src/components/layout/PageShell.tsx4 symbols
browser/src/components/chat/ChatPanel.tsx4 symbols
browser/src/components/ui/ResultDisplay.tsx3 symbols
browser/src/components/ui/CoinBadge.tsx3 symbols
browser/src/components/queries/TokensPanel.tsx3 symbols

Dependencies from manifests, versioned

@tailwindcss/vite4.1.16 · 1×
@types/node22.0.0 · 1×
@types/react19.1.16 · 1×
@types/react-dom19.1.9 · 1×
@types/ws8.18.1 · 1×
@unicitylabs/sphere-ui0.1.23 · 1×
@vitejs/plugin-react5.0.4 · 1×
lucide-react0.400.0 · 1×
react19.1.1 · 1×
react-dom19.2.4 · 1×
tailwindcss4.1.16 · 1×

For agents

$ claude mcp add sphere-sdk-connect-example \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact