Integration Example

Here's an example of how to create a Token Bound Account using WalletConnect:

import { AxesConnect } from 'axes-connect-sdk';

async function createTBA() {
  const axesConnect = new AxesConnect({ apiKey: 'YOUR_API_KEY' });
  
  // 1. Connect wallet
  const session = await axesConnect.wallet.connect();
  
  // 2. Fetch wallet address
  const walletAddress = session.accounts[0];
  
  // 3. Check for existing TBA
  const tbaExists = await axesConnect.tba.checkExistence(walletAddress);
  
  if (!tbaExists) {
    // 4. Create new TBA
    const newTBA = await axesConnect.tba.create(walletAddress);
    
    // 5. Wait for transaction confirmation
    await axesConnect.utils.waitForConfirmation(newTBA.transactionHash);
    
    // 6. Update UI and store data
    console.log('TBA created successfully:', newTBA.address);
    
    // 7. Enable TBA functionalities
    await axesConnect.tba.enableFeatures(newTBA.address);
    
    // 8. Notify user
    axesConnect.notifications.send({
      type: 'TBA_CREATED',
      address: newTBA.address
    });
  } else {
    console.log('TBA already exists for this wallet');
  }
}

createTBA().catch(console.error);

Last updated