Skip to Content

Examples

End-to-end snippets covering the most common SDK flows.

Read On-chain Recipients and Claim Status

import { Connection, PublicKey } from '@solana/web3.js' import { AirdropStudioClient } from '@bonkit/airdrop-sdk' const connection = new Connection('https://api.devnet.solana.com', 'confirmed') const client = await AirdropStudioClient.init({ connection, network: 'devnet', }) const airdrop = new PublicKey('<replace-with-airdrop-address>') const recipients = await client.listOnchainRecipients({ airdrop }) const firstRecipient = recipients[0] console.log(recipients.length) if (firstRecipient) { const claimStatus = await client.fetchClaimStatusFromIndex({ airdrop, entryIndex: firstRecipient.entryIndex, }) console.log(claimStatus) }

Build Merkle Roots for On-chain Registration

import { BN } from '@coral-xyz/anchor' import { Keypair, PublicKey } from '@solana/web3.js' import { buildMerkleRoots } from '@bonkit/airdrop-sdk' const airdrop = new PublicKey('<replace-with-airdrop-address>') const recipients = [ { wallet: Keypair.generate().publicKey, amount: new BN(1_000_000) }, { wallet: Keypair.generate().publicKey, amount: new BN(2_000_000) }, ] const built = buildMerkleRoots(recipients, { airdrop }) console.log(built.rootEntries) console.log(built.trees[0].root.hash)

Use rootEntries when calling registerMerkleRoot, and keep trees if you want to derive claim proofs later.

Store a Compact Serialized Tree and Derive Claim Params on Demand

import { BN } from '@coral-xyz/anchor' import { Keypair, PublicKey } from '@solana/web3.js' import { buildMerkleRoots, createClaimMerkleParamsFromSerializedTree, serializeMerkleRoots, } from '@bonkit/airdrop-sdk' const airdrop = new PublicKey('<replace-with-airdrop-address>') const recipients = [ { wallet: Keypair.generate().publicKey, amount: new BN(1_000_000) }, { wallet: Keypair.generate().publicKey, amount: new BN(2_000_000) }, ] const built = buildMerkleRoots(recipients, { airdrop }) const serialized = serializeMerkleRoots(built) console.log(serialized.rootEntries[0].leafCount) const firstRoot = serialized.trees[0] const claimParams = createClaimMerkleParamsFromSerializedTree(firstRoot, 0) console.log(claimParams.rootIndex) console.log(claimParams.leafIndex) console.log(claimParams.proof.length)

This is usually better than fully materialized payloads for large recipient sets — the serialized tree stores each node once and derives proofs only when needed.

Build a Claim Transaction with the Client

import { BN } from '@coral-xyz/anchor' import { Connection, Keypair, PublicKey } from '@solana/web3.js' import { AirdropStudioClient, createClaimMerkleParamsFromSerializedTree, } from '@bonkit/airdrop-sdk' const connection = new Connection('https://api.devnet.solana.com', 'confirmed') const payer = Keypair.generate() const claimant = Keypair.generate() const client = await AirdropStudioClient.init({ connection, network: 'devnet', }) const airdrop = new PublicKey('<replace-with-airdrop-address>') const mint = new PublicKey('<replace-with-mint-address>') const serializedTree = JSON.parse('<serialized tree JSON>') const claimParams = createClaimMerkleParamsFromSerializedTree(serializedTree, 0) const tx = await client.claimMerkleTokens({ params: claimParams, accounts: { airdrop, mint, claimant: claimant.publicKey, }, payer: payer.publicKey, signers: [payer, claimant], }) console.log(tx)

Send the transaction via connection.sendTransaction(tx) once you are ready.

Next Step

This concludes the SDK walkthrough. If you skipped them earlier, circle back to Validation and Errors for the recommended error-handling pattern around sendTransaction, or PDAs for deterministic address derivation.

Last updated on