Dynamic offers full Spark wallet support through the @dynamic-labs/spark package, enabling seamless integration with Spark network wallets including Magic Eden and other Bitcoin-based wallets.

Installation

First, install the Spark wallet connector package:
npm install @dynamic-labs/spark

Supported Wallets

Magic Eden

The package includes full support for Magic Eden’s Spark wallet implementation, which provides:
  • Connection Management - Seamless wallet connection and disconnection
  • Address Retrieval - Get current wallet address
  • Message Signing - Sign messages for authentication with optional Taproot support
  • Bitcoin Transfers - Send Bitcoin to other Spark addresses
  • Token Transfers - Transfer tokens between Spark addresses

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.

Basic Integration

To use Spark wallets in your app, add the Spark wallet connectors to your Dynamic configuration:
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>
  );
}

Check if a wallet is a Spark wallet

The first thing you should do is check if the wallet is a Spark wallet. You can use the isSparkWallet helper method for that. That way, TypeScript will know which methods etc. are available to you.
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isSparkWallet } from '@dynamic-labs/spark';

const { wallet } = useDynamicContext();

if (!isSparkWallet(wallet)) {
  throw new Error('This wallet is not a Spark wallet');
}

Fetch the wallet address

You can get the wallet address using the wallet.address property:
const { primaryWallet } = useDynamicContext();

const sparkAddress = primaryWallet.address;

Send Bitcoin

To send Bitcoin to another Spark address, use the sendBalance or transferBitcoin method:
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isSparkWallet } from '@dynamic-labs/spark';

const { primaryWallet } = useDynamicContext();

const handleSendBitcoin = async () => {
  if (isSparkWallet(primaryWallet)) {
    // Send Bitcoin using sendBalance (alias for transferBitcoin)
    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,
    });
  }
};

Send Tokens

To send tokens to another Spark address, use the transferTokens method:
const handleSendTokens = async () => {
  if (isSparkWallet(primaryWallet)) {
    const txHash = await primaryWallet.transferTokens({
      tokenPublicKey: 'token123',
      receiverSparkAddress: 'sp1recipient123456789abcdef',
      tokenAmount: 1000,
      isTaproot: false,
    });
  }
};

Sign Messages

Spark wallets support message signing for authentication:
const handleSignMessage = async () => {
  if (isSparkWallet(primaryWallet)) {
    // Sign a regular message
    const signature = await primaryWallet.signMessage('Hello, Spark!');
    
    // Sign with Taproot support
    const taprootSignature = await primaryWallet.signMessageWithTaproot('Hello, Spark!');
  }
};

Custom Connector Implementation

To add support for a new Spark wallet, extend the SparkWalletConnector class:
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;
  }
}

API Reference

Core Methods

  • sendBalance(params) - Send Bitcoin (alias for transferBitcoin)
  • transferBitcoin(params) - Send Bitcoin to a Spark address
  • transferTokens(params) - Send tokens to a Spark address
  • signMessage(message) - Sign a message for authentication
  • signMessageWithTaproot(message) - Sign a message with Taproot support

Type Definitions

  • SparkConnectionResult - Result from wallet connection
  • SparkAddressResult - Result from address retrieval
  • SparkSignMessageRequest - Message signing request options
  • SparkSignatureResult - Result from message signing