Generate a Deposit Address

To deposit Bitcoin into your Spark wallet from L1, you’ll first need to generate a deposit address. Once you have a deposit address, you can send Bitcoin to it. As deposited funds are mapped to the Spark statechain, Spark deposit address can only be used a single time.

Once the transaction is confirmed, you can claim the deposit by calling claimDeposit(txId). Once claimed you can call getBalance() to view the updated balance. For Layer 1 Bitcoin deposits, Spark generates Pay to Taproot (P2TR) addresses. These addresses start with “bc1p” for mainnet and can be used to receive Bitcoin from any wallet.

Mainnet Address Example: bc1p5d7rjq7g6rdk2yhzks9smtbqtedr4dekq08ge8ztwac72sfr9rusxg3297

Code Sample:

const depositAddress = await wallet.getSingleUseDepositAddress();
console.log("Deposit Address:", depositAddress);

Watch for the deposit transaction

After sending Bitcoin to the deposit address, you can watch the mempool for the transaction to be confirmed.

use below utility function to poll the mempool for the transaction to be confirmed.

import { getLatestDepositTxId } from "@buildonspark/spark-sdk/utils";
const result = await getLatestDepositTxId(depositAddress);

Once confirmed, you can run claimDeposit(txId) to claim the deposit and view the balance.

if (result) {
  console.log("Transaction ID: ", result);
  const tx = await wallet.claimDeposit(result);
}

const balance = await wallet.getBalance();
console.log(`Balance:`, balance);

The getBalance() method returns a Promise resolving to an object containing:

  • balance: A bigint representing the total amount in satoshis
  • tokenBalances: A Map of token balances, where each entry contains:
    • balance: A bigint representing the token amount

Confirmation Requirements

  • Deposits require 3 confirmations on L1
  • Once you’re deposit is final you’ll receive BTC on Spark
  • Funds will be available in your Spark wallet after confirmation

Best Practices

  • Start with a small test amount for your first deposit
  • Keep track of your deposit transaction IDs
  • Wait for the required confirmations before considering the deposit complete

Next Steps

Once your deposit is confirmed, you can:

Need Help?