Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

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

关于 About

No description, website, or topics provided.

语言 Languages

TypeScript99.4%
CSS0.3%
HTML0.3%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
64
Total Commits
峰值: 23次/周
Less
More

核心贡献者 Contributors