@canton-network/dapp-sdk

中文文档
1.9.0发布于 2026/11/06Apache-2.0TypeScriptESM + CJS近 30 天下载 2.2万

Browser SDK for dApp development on the Canton Network

原始使用文档
文档目录16 节
  1. Features
  2. Installation
  3. Quick Start
  4. Architecture
  5. Wallet providers
  6. Usage
  7. Option A: Module-level API (recommended for most apps)
  8. Option B: DappClient with DiscoveryClient
  9. Option C: DappClient with a provider directly
  10. API Reference
  11. DappClient
  12. DappClientOptions
  13. DiscoveryClient
  14. Built-in Adapters
  15. Documentation
  16. License

dApp SDK

@canton-network/dapp-sdk — TypeScript SDK for building decentralized applications on the Canton Network. Connect users to Canton wallets, manage accounts, sign messages, and execute transactions — all through a vendor-neutral interface defined by CIP-0103.

[!NOTE] Migration guides for each release are published in Discussions.

Features

  • Wallet Discovery — Remote gateways, EIP-6963-style canton:announceProvider events, and pluggable adapters
  • Wallet Picker UI — Built-in, framework-agnostic Web Component that lets users choose a wallet, enter custom gateway URLs, and manage recently used connections
  • Wallet Connectivity — Connect, disconnect, and monitor connection status
  • Account Management — List accounts and respond to account changes
  • Transaction Execution — Request user approval and signatures for Daml transactions
  • Ledger API Access — Proxy authenticated requests to the Canton JSON Ledger API
  • Real-time Events — Subscribe to status changes, account changes, and transaction lifecycle events
  • Multi-transport — HTTP/SSE for remote Wallet Gateways, postMessage for browser extension wallets
  • Provider Interface — EIP-1193-style CIP-103 provider via getConnectedProvider() after connect()

Installation

npm install @canton-network/dapp-sdk
pnpm add @canton-network/dapp-sdk

Quick Start

The fastest way to get going is through the module-level convenience API. It manages a singleton DappClient behind the scenes, opens the wallet picker, and handles adapter registration for you.

import * as sdk from '@canton-network/dapp-sdk'

// Opens the wallet picker and connects to the selected wallet
const result = await sdk.connect()
console.log(result.isConnected)

// List the user's accounts (parties)
const accounts = await sdk.listAccounts()

// Execute a transaction
await sdk.prepareExecute({
    commands: [
        {
            CreateCommand: {
                templateId: '#MyApp:MyModule:MyTemplate',
                createArguments: { owner: accounts[0].partyId },
            },
        },
    ],
})

// Listen for real-time updates
sdk.onTxChanged((tx) => {
    console.log('Transaction update:', tx)
})

// Disconnect when done
await sdk.disconnect()

Architecture

The SDK is built around three layers:

┌──────────────────────────────────────────────┐
│  DappClient                                  │
│  Thin wrapper: typed RPC helpers, events,    │
│  session persist                             │
├──────────────────────────────────────────────┤
│  DiscoveryClient                             │
│  Adapter registry, session restore,          │
│  wallet picker integration                   │
├──────────────────────────────────────────────┤
│  ProviderAdapter implementations             │
│  ExtensionAdapter (announce protocol)        │
│  (browser / postMessage)                     │
│  RemoteAdapter (HTTP/SSE gateway)            │
└──────────────────────────────────────────────┘

Wallet providers

Wallet and extension authors: see Wallet providers (discovery) in the dApp Building docs for how to appear in the picker (RemoteAdapter, canton:announceProvider, and additionalAdapters).

Usage

Import the SDK as a namespace. The connect() function opens the built-in wallet picker, registers available adapters, and returns a ConnectResult.

import * as sdk from '@canton-network/dapp-sdk'
import { RemoteAdapter } from '@canton-network/dapp-sdk'

await sdk.connect()
const status = await sdk.status()

You can supply additional adapters at connect time:

await sdk.connect({
    additionalAdapters: [
        new RemoteAdapter({
            name: 'My Gateway',
            rpcUrl: 'https://gateway.example.com/api/json-rpc',
        }),
    ],
})

Option B: DappClient with DiscoveryClient

For more control over adapter registration and the connection flow, use DiscoveryClient directly and pass the resulting provider to DappClient.

import {
    DappClient,
    DiscoveryClient,
    RemoteAdapter,
} from '@canton-network/dapp-sdk'

const discovery = await DiscoveryClient.create({
    adapters: [
        new RemoteAdapter({
            name: 'Splice Wallet Gateway',
            rpcUrl: 'https://gateway.example.com/api/json-rpc',
        }),
    ],
})
await discovery.connect() // opens the picker if configured

const session = discovery.getActiveSession()!
const client = new DappClient(session.provider, {
    providerType: session.adapter.type,
})

const status = await client.status()

Option C: DappClient with a provider directly

If you already have a Provider<DappRpcTypes> (for example from your own adapter), you can skip discovery entirely.

import { DappClient, RemoteAdapter } from '@canton-network/dapp-sdk'

const provider = new RemoteAdapter({
    name: 'Splice Wallet Gateway',
    rpcUrl: 'https://gateway.example.com/api/json-rpc',
}).provider()

const client = new DappClient(provider)
const result = await client.connect()

API Reference

DappClient

MethodReturnsDescription
connect()ConnectResultInitiate connection via the provider
disconnect()voidDisconnect and clear local state
status()StatusEventCurrent connection status
listAccounts()ListAccountsResultList the user's accounts (parties)
prepareExecute(params)nullSubmit a transaction for signing
prepareExecuteAndWait(params)PrepareExecuteAndWaitResultSubmit and wait for completion
ledgerApi(params)LedgerApiResultProxy a Ledger API request
open()voidOpen the wallet UI
getProvider()ProviderAccess the underlying provider
onStatusChanged(listener)voidSubscribe to status changes
onAccountsChanged(listener)voidSubscribe to account changes
onTxChanged(listener)voidSubscribe to transaction changes

DappClientOptions

OptionTypeDefaultDescription
providerTypeProviderType'remote'Affects open() routing ('browser' uses postMessage, others use popup)

DiscoveryClient

MethodDescription
create(config)Create an initialized client and attempt session restore
registerAdapter(adapter)Add a ProviderAdapter at runtime
listAdapters()List registered adapters
connect(providerId?)Connect to a specific adapter or open the picker
disconnect()Disconnect the active session
getActiveSession()Get the current ActiveSession or null
on(event, handler)Listen for discovery:connected, discovery:disconnected, discovery:error
removeListener(event, handler)Remove an event listener

Built-in Adapters

AdapterProvider TypeTransportDescription
ExtensionAdapter'browser'postMessageBrowser extensions discovered via canton:announceProvider (Wallet providers guide).
RemoteAdapter'remote'HTTP/SSECIP-103 Wallet Gateways over the network.

Documentation

Full documentation, including detailed usage guides, API reference, and configuration for the Wallet Gateway:

License

Apache-2.0

版本与发布记录

@canton-network/dapp-sdk 共发布 49 个版本,首次发布于 2025/08/29;过去 12 个月发布了 34 个版本。

版本发布日期距今
1.9.0latest2026/11/063 天前
1.8.02026/10/1227 天前
1.7.12026/09/111 个月前
1.7.02026/09/101 个月前
1.6.02026/09/052 个月前
1.5.12026/08/132 个月前

关于 @canton-network/dapp-sdk 的常见问题

@canton-network/dapp-sdk 是什么?

Browser SDK for dApp development on the Canton Network

如何安装 @canton-network/dapp-sdk?

在项目目录运行 npm install @canton-network/dapp-sdk,或使用 pnpm add / yarn add / bun add。

@canton-network/dapp-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@canton-network/dapp-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@canton-network/dapp-sdk 可以商用吗?

@canton-network/dapp-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@canton-network/dapp-sdk 的下载量有多少?

根据 npm 官方下载统计,@canton-network/dapp-sdk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 22,046 次,日均约 735 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@canton-network/dapp-sdk 还在维护吗?

最新版本 1.9.0 发布于 2026/11/06(3 天前);至今共发布 49 个版本,其中过去 12 个月发布了 34 个;首次发布于 2025/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。