Airdrop
Merkle-proof whitelist token distribution
Pending
Anchor 0.32
Program ID
CNcG4AK4uUXsqAjKQiFk5i9zU75MdHmgdJDXa5cCgYDH
Repository
ExpertVagabond/solana-airdrop
Binary Size
296K
Cluster
Devnet
Instructions
IX
create_airdrop
Creates a new airdrop campaign with a merkle root for whitelist verification.
| Parameter | Type | Description |
|---|---|---|
amount_per_claim | u64 | Token amount each eligible wallet can claim |
max_claims | u64 | Maximum total number of claims allowed |
merkle_root | [u8; 32] | Root hash of the merkle tree containing eligible wallets |
IX
fund_airdrop
Deposits tokens into the airdrop vault to fund the distribution.
| Parameter | Type | Description |
|---|---|---|
amount | u64 | Number of tokens to deposit |
IX
claim
Claims tokens from the airdrop. Requires a valid merkle proof to verify eligibility.
| Parameter | Type | Description |
|---|---|---|
proof | Vec<[u8; 32]> | Merkle proof path from leaf to root |
IX
close_airdrop
Closes the airdrop and returns remaining tokens to the authority. Only callable by the authority.
| Parameter | Type | Description |
|---|---|---|
| No parameters | ||
Accounts
Airdrop
| Field | Type | Description |
|---|---|---|
authority | Pubkey | Airdrop creator and admin |
mint | Pubkey | Token mint being distributed |
amount_per_claim | u64 | Tokens per eligible claim |
max_claims | u64 | Maximum number of claims allowed |
total_claimed | u64 | Number of claims made so far |
merkle_root | [u8; 32] | Merkle root for whitelist verification |
active | bool | Whether the airdrop is currently active |
bump | u8 | PDA bump seed |
ClaimRecord
| Field | Type | Description |
|---|---|---|
airdrop | Pubkey | The airdrop this claim belongs to |
claimer | Pubkey | Wallet that claimed |
amount | u64 | Amount of tokens claimed |
claimed_at | i64 | Timestamp of the claim |
bump | u8 | PDA bump seed |
PDA Derivation
airdrop
seeds = [b"airdrop", authority, mint]
claim
seeds = [b"claim", airdrop, claimer]
vault
seeds = [b"vault", airdrop]
Error Codes
NotActive
The airdrop has been closed and is no longer accepting claims
MaxClaimsReached
All available claim slots have been used
InvalidProof
The provided merkle proof does not verify against the root
Overflow
Arithmetic overflow in claim tracking
Usage Example
import { Program, BN } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; import { MerkleTree } from "merkletreejs"; import { keccak256 } from "js-sha3"; // Build merkle tree from whitelist const whitelist = [wallet1, wallet2, wallet3]; const leaves = whitelist.map(w => keccak256(w.toBuffer())); const tree = new MerkleTree(leaves, keccak256, { sortPairs: true }); const root = tree.getRoot(); // Create airdrop with 1000 tokens per claim, 500 max claims const [airdropPda] = PublicKey.findProgramAddressSync( [Buffer.from("airdrop"), authority.publicKey.toBuffer(), mint.toBuffer()], program.programId ); await program.methods .createAirdrop(new BN(1_000_000_000), new BN(500), [...root]) .accounts({ airdrop: airdropPda, authority: authority.publicKey, mint, }) .signers([authority]) .rpc(); // Claim with merkle proof const proof = tree.getProof(keccak256(claimer.publicKey.toBuffer())) .map(p => [...p.data]); await program.methods .claim(proof) .accounts({ airdrop: airdropPda, claimer: claimer.publicKey, mint, }) .signers([claimer]) .rpc();