Skip to main content
In this guide, you’ll learn how to claim fees for a specific token using the Bags TypeScript SDK with Node.js. The simplified claim flow only requires a token mint address and your wallet — the API handles the rest.

Prerequisites

Before starting, make sure you have:

1. Set Up Environment Variables

This guide requires your wallet’s private key. Add it to your base .env file:
You can export your private key from wallets like Bags, Phantom, or Backpack.

2. The Fee Claiming Script

Here is a script to claim fees for a specific token. You can save this as claim-fees.ts. The claim flow is straightforward — pass your wallet and the token mint to the SDK and you’ll receive ready-to-sign transactions back.

Endpoints Used Under the Hood

This guide uses these API endpoints via the SDK:

3. How It Works

The SDK’s getClaimTransactions() method handles all the complexity for you:
  1. You provide: Your wallet and the token mint
  2. The API automatically: Looks up your claimable position, determines the position type (virtual pool, DAMM V2, custom fee vault), and builds the appropriate claim transactions
  3. You receive: An array of versioned transactions ready to sign and send

4. Checking Claimable Positions (Optional)

If you want to inspect your claimable positions before claiming — for example, to check claimable amounts or see which tokens have fees available — you can use the SDK’s getAllClaimablePositions() method:
This is useful for building UIs that display fee balances, or for deciding which tokens to claim fees for.

Alternative: Using the Bags CLI

This section requires the Bags CLI. See Install and Set Up the Bags CLI to get started.
The CLI lets you view and claim fees without writing scripts: List all claimable positions:
Claim fees for a specific token:
Claim all available fees across every token:
Add --skip-confirm to either claim command to bypass the confirmation prompt (useful for automation).

5. Running the Script

Replace TOKEN_MINT with the token mint address you want to claim fees for, then run:
The script will automatically generate and send claim transactions for the specified token using your wallet.

6. Error Handling

Common errors you may encounter:
  • No claimable fees: The wallet has no fees to claim for the specified token
  • Invalid token mint: The token mint address is not a valid Solana public key
  • Insufficient SOL: Your wallet needs SOL for transaction fees
  • Rate limiting: Respect API rate limits between requests
Check the console output for detailed error messages.