Receiving Spark Payments

Spark ↔ Spark transfers, use Spark Addresses to identify the receiving wallet. To receive a payment, you’ll need to get your Spark wallet address and share it with the sender. The Spark Address format is similar to the usual Bitcoin address format: Address Example: sprt1pgssyuuuhnrrdjswal5c3s3rafw9w3y5dd4cjy3duxlf7hjzkp0rqx6dj6mrhu Checkout Spark Addresses for more details. Code Sample:
const sparkAddress = await wallet.getSparkAddress();
console.log("Spark Address:", sparkAddress);

Sending Spark Payments

Send Bitcoin payments to other Spark wallets:
const transfer = await wallet.transfer({
  receiverSparkAddress:
    "sprt1pgssyuuuhnrrdjswal5c3s3rafw9w3y5dd4cjy3duxlf7hjzkp0rqx6dj6mrhu",
  amountSats: 100,
});

console.log("Transfer:", transfer);
Using a Spark Wallet you can also send and receive Tokens to other Spark users:
 const transfer = await wallet.transferTokens({
        tokenIdentifier: "btkn1qwertyuiopasdfghjklzxcvbnm1234567890abcdef",
        tokenAmount: 100n,
        receiverSparkAddress: "sprt1pgssyuuuhnrrdjswal5c3s3rafw9w3y5dd4cjy3duxlf7hjzkp0rqx6dj6mrhu"
  });

console.log("Transfer:", transfer);

Receiving Spark Payments

To check balance after a transfer, use the getBalance() method.
// Check updated balance
const balance = await wallet.getBalance();
console.log("New 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:
    • The public key of the token
    • An object with bigint representing the token amount along with some token information
Additionally, you can listen for balance update events.
wallet.on("transfer:claimed", (transferId: string, balance: number) => {
  console.log(
    `Transfer ${transferId} claimed. New balance: ${balance}`,
  );
});

Features and Benefits

  • Instant settlements
  • Lower fees compared to on-chain transactions
  • Standard pubkey addressing system

Need Help?