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.Documentation Index
Fetch the complete documentation index at: https://docs.bags.fm/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before starting, make sure you have:- Completed our TypeScript and Node.js Setup Guide.
- Got your API key from the Bags Developer Portal.
- A Solana wallet with claimable fees (from token launches, liquidity pools, etc.).
- Installed the additional dependencies for this guide:
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 asclaim-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:POST /token-launch/claim-txs/v3viasdk.fee.getClaimTransactions()GET /token-launch/claimable-positionsviasdk.fee.getAllClaimablePositions()
3. How It Works
The SDK’sgetClaimTransactions() method handles all the complexity for you:
- You provide: Your wallet and the token mint
- 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
- 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’sgetAllClaimablePositions() method:
Alternative: Using the Bags CLI
This section requires the Bags CLI. See Install and Set Up the Bags CLI to get started.
--skip-confirm to either claim command to bypass the confirmation prompt (useful for automation).
5. Running the Script
ReplaceTOKEN_MINT with the token mint address you want to claim fees for, then run:
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
