Overview

Receiving payments with Arkade is simple and efficient. Your wallet can generate addresses for both on-chain and off-chain (Ark) payments, allowing your users to send Bitcoin to you through either method.

Getting Your Wallet Address

To receive payments, you first need to generate an address:

// Get both on-chain and off-chain addresses
const addresses = await wallet.getAddress()

// The off-chain Ark address for instant payments
console.log('Ark Address:', addresses.offchain)

// The on-chain Bitcoin address
console.log('Bitcoin Address:', addresses.onchain)

Ark Addresses

Ark addresses start with ark1 on Bitcoin mainnet or tark1 on testnet and regtest.

Understanding Ark Addresses

Learn about the technical structure of Ark addresses, how they’re generated, and the security guarantees they provide.

Monitoring for Incoming Payments

To detect when payments are received, you can use the subscription API to monitor your address for incoming transactions in real-time.

Setting Up a Subscription

try {
  // Create an abort controller to manage the subscription lifecycle
  const abortController = new AbortController();
  
  // Subscribe to updates for your address
  const addresses = await wallet.getAddress();
  const subscription = arkProvider.subscribeForAddress(
    addresses.offchain,
    abortController.signal
  );
  
  // Process updates as they arrive
  for await (const update of subscription) {
    const vtxos = [...update.newVtxos, ...update.spentVtxos];
    if (vtxos.length === 0) {
      continue;
    }
    
    // Process the received VTXOs
    console.log('New VTXOs received:', update.newVtxos.length);
    console.log('VTXOs spent:', update.spentVtxos.length);
    
    // Process new payments
    await processNewVtxos(update.newVtxos);
  }
} catch (error) {
  console.error("Error processing address updates:", error);
}

Processing Payment Updates

When a payment is received, you’ll want to process the update and take appropriate actions:

// Example function to process new VTXOs
async function processNewVtxos(newVtxos) {
  // Update your application state
  for (const vtxo of newVtxos) {
    console.log(`Received payment of ${vtxo.amount} sats`);
    
    // You might want to store the VTXO in your database
    await storeVtxoInDatabase(vtxo);
    
    // Notify the user
    showNotification(`Received ${vtxo.amount} sats!`);
    
    // Update the UI
    await refreshBalanceDisplay();
  }
}

Cleaning Up Subscriptions

When your application no longer needs to listen for updates, make sure to clean up the subscription:

// Clean up the subscription when done
abortController.abort();

This is important to prevent memory leaks and unnecessary network traffic, especially when your application is closing or navigating away from the payment screen.

Best Practices

Next Steps