> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Spark Wallets

<Card title="Recommended: JavaScript SDK with React Hooks" icon="react" color="#4779FE">
  For new React apps, we recommend the JavaScript SDK with React Hooks (`@dynamic-labs-sdk/react-hooks`) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the [React quickstart (JavaScript SDK)](/javascript/reference/react-quickstart) to get started.
</Card>

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:

```bash theme={"system"}
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

| Network     | Chain ID | Description        | Block Explorer                         |
| ----------- | -------- | ------------------ | -------------------------------------- |
| **Mainnet** | 301      | Production network | [mempool.space](https://mempool.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:

```ts theme={"system"}
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.

```ts theme={"system"}
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:

```ts theme={"system"}
const { primaryWallet } = useDynamicContext();

const sparkAddress = primaryWallet.address;
```

## Send Bitcoin

To send Bitcoin to another Spark address, use the `sendBalance` or `transferBitcoin` method:

```ts theme={"system"}
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:

```ts theme={"system"}
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:

```ts theme={"system"}
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:

```ts theme={"system"}
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
