Depositing BTC into Your Wallet

  1. Get Deposit Address

    To transfer funds into Spark, you will first need to get a deposit address. This address is a regular P2TR address based on the network you are connected to. This function is exposed in the SDK as initiateDeposit.

    const initiateDepositPackage = await sparkWallet.initiateDeposit(BigInt(20_000));
    const depositAddress = initiateDepositPackage.depositAddress;
    

    Please note that the response from initiateDeposit() is needed to complete the deposit.

  2. Send Funds to the Deposit Address

    Send the requested amount of BTC to the deposit address. You can use any Bitcoin wallet to send the funds. For regtest, you can easily faucet the funds directly to your deposit address using the faucetToAddress() function.

    let depositAddress = "<deposit address from initiateDeposit()>";
    const { txid: faucetToDepositAddressTxid, vout: faucetToDepositAddressVout } = await sparkWallet.faucetToAddress(BigInt(20_000), depositAddress);
    
  3. Complete the Deposit

    Once the funds are sent to the deposit address, you can complete the deposit by calling completeDeposit with the initiateDeposit response and the txid of the transaction that sent the funds to the deposit address. For regtest, this txid is the same as the one returned from the faucet. Note that when using faucet, the wallet should sleep a few seconds before calling completeDeposit to ensure the funds are confirmed.

    await sparkWallet.completeDeposit(faucetToDepositAddressTxid,initiateDepositPackage);
    

Next Steps

Proceed to Send & Receive on Lightning to learn how to send and receive payments via the Lightning Network.