@dynamic-labs/spark

中文文档
5.16.1发布于 2026/11/13MITTypeScriptESM + CJS近 30 天下载 4832

A React SDK for implementing wallet web3 authentication and authorization to your website.

原始使用文档
文档目录25 节
  1. Features
  2. Installation
  3. Architecture
  4. Base Connector Class
  5. Provider Interface
  6. 🌐 Supported Networks
  7. 📖 Usage
  8. Basic Integration
  9. Using the SparkWallet
  10. Custom Connector Implementation
  11. Type Checking
  12. 🧪 Testing
  13. Run Tests
  14. Build Package
  15. Test in Demo App
  16. 📚 API Reference
  17. Core Exports
  18. SparkWallet Methods
  19. Type Definitions
  20. 🔗 Related Packages
  21. 🤝 Contributing
  22. Development Setup
  23. Adding New Wallets
  24. 📄 License
  25. 🆘 Support

@dynamic-labs/spark

A Spark wallet connector package for the Dynamic SDK that enables seamless integration with Spark network wallets.

Features

  • Flexible Provider Interface - Easy to add support for additional Spark wallets
  • Bitcoin Transfers - Send Bitcoin to Spark addresses with optional Taproot support
  • Token Transfers - Transfer tokens between Spark addresses
  • Message Signing - Sign messages for authentication with optional Taproot support
  • Mainnet Support - Currently supports Spark mainnet (chain ID 301)

Installation

npm install @dynamic-labs/spark

Architecture

Base Connector Class

The SparkWalletConnector provides a robust foundation for all Spark wallet integrations:

  • Abstract Implementation - Handles common wallet operations
  • Error Handling - Comprehensive error handling and logging
  • Mainnet Focus - Currently optimized for mainnet usage

Provider Interface

All Spark wallet providers must implement the ISparkProvider interface:

interface ISparkProvider {
  isConnected: boolean;
  chainId?: string;
  network?: string;

  connect(): Promise<SparkConnectionResult | string>;
  disconnect(): Promise<void>;
  getAddress(): Promise<SparkAddressResult>;
  signMessage(
    message: string | SparkSignMessageRequest,
  ): Promise<SparkSignatureResult>;
  signMessageWithTaproot(message: string): Promise<SparkSignatureResult>;
  transferBitcoin(params: {
    receiverSparkAddress: string;
    amountSats: bigint;
    isTaproot?: boolean;
  }): Promise<string>;
  transferTokens(params: {
    tokenPublicKey: string;
    receiverSparkAddress: string;
    tokenAmount: number;
    isTaproot?: boolean;
  }): Promise<string>;
  request(method: string, params?: unknown): Promise<unknown>;

  [key: string]: unknown; // Extensible for additional properties
}

🌐 Supported Networks

NetworkChain IDDescriptionBlock Explorer
Mainnet301Production networkmempool.space

Note: Currently only mainnet is supported. Testnet, signet, and regtest support may be added in future versions.

📖 Usage

Basic Integration

import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core';
import { SparkWalletConnectors } from '@dynamic-labs/spark';

function App() {
  return (
    <DynamicContextProvider
      settings={{
        environmentId: 'your-environment-id',
        walletConnectors: [SparkWalletConnectors()],
      }}
    >
      {/* Your app content */}
    </DynamicContextProvider>
  );
}

Using the SparkWallet

import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { SparkWallet } from '@dynamic-labs/spark';

function MyComponent() {
  const { primaryWallet } = useDynamicContext();

  const handleSendBitcoin = async () => {
    if (primaryWallet instanceof SparkWallet) {
      // Send Bitcoin
      const txHash = await primaryWallet.sendBalance({
        amount: '100000', // 100,000 satoshis
        toAddress: 'sp1recipient123456789abcdef',
        isTaproot: false,
      });

      // Or use the direct transferBitcoin method
      const txHash2 = await primaryWallet.transferBitcoin({
        amount: '50000',
        toAddress: 'sp1recipient123456789abcdef',
        isTaproot: true,
      });
    }
  };

  const handleSendTokens = async () => {
    if (primaryWallet instanceof SparkWallet) {
      const txHash = await primaryWallet.transferTokens({
        tokenPublicKey: 'token123',
        receiverSparkAddress: 'sp1recipient123456789abcdef',
        tokenAmount: 1000,
        isTaproot: false,
      });
    }
  };

  return (
    <div>
      <button onClick={handleSendBitcoin}>Send Bitcoin</button>
      <button onClick={handleSendTokens}>Send Tokens</button>
    </div>
  );
}

Custom Connector Implementation

To add support for a new Spark wallet:

import { SparkWalletConnector } from '@dynamic-labs/spark';

export class YourSparkConnector extends SparkWalletConnector {
  override name = 'Your Spark Wallet';
  override overrideKey = 'yourspark';

  public override getProvider(): ISparkProvider | undefined {
    return window.yourProvider;
  }
}

Type Checking

Use the isSparkWallet type guard to safely work with Spark wallets:

import { isSparkWallet } from '@dynamic-labs/spark';

function handleWallet(wallet: Wallet) {
  if (isSparkWallet(wallet)) {
    // TypeScript now knows this is a SparkWallet
    wallet.transferBitcoin({
      amount: '100000',
      toAddress: 'sp1recipient123456789abcdef',
    });
  }
}

🧪 Testing

Run Tests

npx nx test spark

Build Package

npx nx build spark

Test in Demo App

  1. Start the demo app: npm run start
  2. Navigate to the Spark wallet section
  3. Test connection, address retrieval, and message signing

📚 API Reference

Core Exports

  • SparkWalletConnectors() - Factory function returning all available connectors
  • SparkWalletConnector - Base class for custom implementations
  • SparkWallet - Wallet class with Bitcoin and token transfer methods
  • ISparkProvider - Interface for wallet providers
  • isSparkWallet - Type guard for Spark wallets

SparkWallet Methods

  • sendBalance(params) - Send Bitcoin (alias for transferBitcoin)
  • transferBitcoin(params) - Send Bitcoin to a Spark address
  • transferTokens(params) - Send tokens to a Spark address

Type Definitions

  • SparkConnectionResult - Result from wallet connection
  • SparkAddressResult - Result from address retrieval
  • SparkSignMessageRequest - Message signing request options
  • SparkSignatureResult - Result from message signing
  • @dynamic-labs/sdk-react-core - React SDK core functionality
  • @dynamic-labs/wallet-connector-core - Base wallet connector classes
  • @dynamic-labs/types - Common type definitions

🤝 Contributing

We welcome contributions! Please see our contributing guidelines for details.

Development Setup

  1. Clone the repository
  2. Install dependencies: npm install
  3. Run tests: npx nx test spark
  4. Build package: npx nx build spark

Adding New Wallets

  1. Create a new connector class extending SparkWalletConnector
  2. Implement the getProvider() method
  3. Add comprehensive tests
  4. Update the SparkWalletConnectors() factory function

📄 License

This package is part of the Dynamic SDK and follows the same licensing terms. See LICENSE for details.

🆘 Support


Built with ❤️ by the Dynamic Labs team

版本与发布记录

@dynamic-labs/spark 共发布 216 个版本,首次发布于 2025/09/03;过去 12 个月发布了 179 个版本。

版本发布日期距今
5.16.1latest2026/11/13今天
5.16.02026/11/112 天前
5.15.12026/11/103 天前
5.15.02026/11/103 天前
4.104.0v4-lts2026/11/0310 天前
5.14.02026/10/3014 天前

其他发布通道:alpha → 4.83.2-alpha.0,rc → 5.0.0-rc.4,v4-lts → 4.104.0。

关于 @dynamic-labs/spark 的常见问题

@dynamic-labs/spark 是什么?

A React SDK for implementing wallet web3 authentication and authorization to your website.

如何安装 @dynamic-labs/spark?

在项目目录运行 npm install @dynamic-labs/spark,或使用 pnpm add / yarn add / bun add。

@dynamic-labs/spark 支持 TypeScript 吗?

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

@dynamic-labs/spark 支持 ESM 还是 CommonJS?

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

@dynamic-labs/spark 可以商用吗?

@dynamic-labs/spark 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dynamic-labs/spark 的下载量有多少?

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

@dynamic-labs/spark 还在维护吗?

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