NFT operations and Merkle token claims
This page describes two token flows: the creation and verification of collection NFTs, and the distribution of tokens to an eligible set of wallets. The NFT flow uses token metadata to connect an NFT to a collection. The claim flow uses a Merkle tree, which is a compact hash-based list, to let each wallet prove its allocation before it receives tokens.
Scope and relationships
These examples show how a token program can coordinate the standard token program with a metadata program or with an off-chain eligibility list. The NFT flow creates the asset and its collection relationship. The Merkle flow creates a fixed distribution pool and pays each approved claim from that pool.
- Token program examples provides the parent view of token use cases.
- Core token operations explains the basic mint and token-account actions used by these flows.
- Token-2022 extensions covers token behavior that extends the base token model.
- Token exchange and fundraising covers flows where token movement supports an exchange or a fund raise.
NFT lifecycle
The NFT lifecycle creates a collection identity, creates a one-of-one NFT that points to that collection, and then confirms the relationship. Each NFT has one token in its token account. Its metadata gives applications a common way to identify the asset and its collection.
Collection creation
The collection creation flow establishes the reference asset for a group of NFTs. It creates a zero-decimal mint, puts one token in the creator's token account, and creates the metadata and master-edition records that describe the mint as a collection.
The mint authority signs the token and metadata actions. The collection metadata marks the asset as a collection and starts its item count at zero. This gives later NFTs a known collection identity to reference.
References: tokens/…/create_collection.rs• L29-64 tokens/…/create_collection.rs• L66-153 tokens/…/create_collection.rs• L16-19 tokens/…/create_collection.rs• L33-92
NFT minting
The NFT minting flow creates another zero-decimal mint and sends one token to the owner's token account. It creates the NFT metadata and master edition in the same transaction flow, then records the collection mint as the NFT's intended collection.
The collection link starts as unverified. This separates the creator's claim that the NFT belongs to a collection from the later proof by the collection authority. The collection mint is therefore the bridge between the individual NFT and the collection asset.
References: tokens/…/mint_nft.rs• L29-66 tokens/…/mint_nft.rs• L68-152 tokens/…/mint_nft.rs• L16-19 tokens/…/mint_nft.rs• L35-107
Collection verification
The verification flow changes an NFT's collection link from unverified to verified. It checks the NFT metadata with the collection mint, collection metadata, and collection master edition, then asks the metadata program to apply the verification.
The collection authority must authorize this step. On success, the NFT metadata records the verified relationship and the collection metadata updates its collection count. The result is a collection membership claim that downstream applications can trust through the metadata record.
References: tokens/…/verify_collection.rs• L18-39 tokens/…/verify_collection.rs• L41-75
The following diagram shows how a collection becomes the verified parent of an NFT.
flowchart LR
A[Create collection mint] --> B[Create collection metadata]
B --> C[Create collection master edition]
C --> D[Mint NFT with collection reference]
D --> E[Collection authority verifies link]
E --> F[Verified collection membership]
Merkle token claim flow
The Merkle token claimer turns a trusted snapshot into a token distribution that users can claim without storing every eligible wallet on chain. A Merkle root is the short value stored on chain. A claimant supplies the amount, leaf position, and sibling hashes needed to prove that their wallet and amount belong to that root.
Eligibility snapshot
The flow begins with a snapshot that maps a source-system holder to a Solana wallet and claim amount. The snapshot keeps source address and snapshot metadata for traceability, while the on-chain leaf uses only the Solana public key and the amount.
The Rust tree generator validates each Solana address and amount before it builds the tree. It skips invalid entries and stops if no valid entry remains. It writes the root, total, and one proof record for each valid entry, so a claim service can give a wallet its proof without giving the chain the complete snapshot.
References: tokens/…/README.md• L7-13 tokens/…/generate_merkle_tree.rs• L11-31 tokens/…/generate_merkle_tree.rs• L82-123 tokens/…/generate_merkle_tree.rs• L125-155 tokens/…/sample-snapshot.json• L1-22
Airdrop setup
The setup flow binds one token mint to one airdrop state. It stores the Merkle root, the total amount available, the authority, and the amount claimed so far. It then mints the full airdrop amount into a vault and removes the mint authority so the pool cannot grow after setup.
The vault is controlled by the airdrop state rather than by a user wallet. The airdrop authority may replace the root only while no claim has been processed. This makes the published root final once distribution starts.
References: tokens/…/README.md• L10-13 tokens/…/README.md• L27-35 tokens/…/lib.rs• L18-63 tokens/…/lib.rs• L113-156
Proof-backed claim
The claim flow binds the submitted amount and wallet to a leaf, rebuilds the root from the supplied proof, and compares that result with the stored root. A valid proof shows eligibility. It does not by itself pay the claimant; the state checks must also show that the indexed claim is new and that the total paid amount stays within the funded airdrop.
When these checks pass, the vault sends the requested amount to the claimant's associated token account. The program then records a claim receipt keyed by the airdrop and leaf index. The receipt and running total make the distribution state visible and prevent the same indexed claim from being processed again.
References: tokens/…/README.md• L12-25 tokens/…/lib.rs• L65-110 tokens/…/lib.rs• L158-199
Merkle proof rules
The tree builder and on-chain verifier must use the same leaf and hash rules. A leaf contains a 32-byte wallet public key followed by an unsigned 64-bit amount in little-endian form. Each tree level hashes a left-right pair. An unpaired node uses a zero hash as its right sibling.
The claim index gives the verifier the order of each pair. The verifier also requires the proof to consume the full index, so a proof cannot be reused at an unrelated deeper index. These rules make the proof result specific to one wallet, amount, and leaf position.
References: tokens/…/README.md• L47-56 tokens/…/generate_merkle_tree.rs• L33-75 tokens/…/lib.rs• L238-269
The following diagram shows how an off-chain eligibility result becomes an on-chain token payment.
sequenceDiagram
participant S as Snapshot source
participant B as Tree builder
participant P as Airdrop program
participant W as Eligible wallet
participant V as Token vault
S->>B: Provide wallet and amount entries
B->>B: Validate entries and build root
B->>P: Store root and fund vault
B-->>W: Provide amount, index, and proof
W->>P: Submit claim
P->>P: Rebuild root and check claim state
P->>V: Transfer approved amount
V-->>W: Deposit tokens
P-->>W: Record claim receipt and total claimed
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the off-chain leaf encoding, pair order, odd-level padding, and proof depth aligned with the on-chain verifier. A mismatch makes valid snapshot entries unclaimable.
- Treat the airdrop root, mint, vault authority, and claim-receipt seed as one contract. Changing one without the others can redirect claims or break replay protection.
- Keep the NFT metadata collection reference and the collection verification inputs aligned. A mint can exist without becoming a verified collection member.
- Preserve the setup boundary that prevents a root update after claims begin. Moving that boundary changes the meaning of already issued proofs.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The snapshot builder and claim program use different leaf or padding rules | Eligible claims fail proof validation | Shared leaf encoding and zero-hash padding rules |
| A claimant submits a wrong amount or index | The computed root does not match the stored root | Root comparison and full index-depth check |
| A claim is submitted again for the same indexed receipt | The second distribution is rejected | Claim receipt state and AlreadyClaimed check |
| The sum of accepted claims exceeds the funded distribution | The claim is rejected before transfer | Checked addition and total-allocation limit |
| The collection authority does not verify the NFT | The NFT remains an unverified collection reference | Authorized collection verification step |
| The root is changed after distribution starts | Existing user proofs could no longer describe one stable allocation set | Root updates are allowed only when the claimed total is zero |
Key files
| File | Why to read it |
|---|---|
| tokens/…/lib.rs | Shows the three public NFT lifecycle operations and their order. |
| tokens/…/create_collection.rs | Shows how a collection mint becomes a metadata-backed collection asset. |
| tokens/…/mint_nft.rs | Shows how an individual NFT gets its collection reference. |
| tokens/…/verify_collection.rs | Shows how collection authority turns the reference into verified membership. |
| tokens/…/create_collection.rs | Shows the parallel low-level collection creation flow. |
| tokens/…/mint_nft.rs | Shows the parallel low-level NFT minting flow and its unverified collection reference. |
| tokens/…/package.json | Defines the build, test, and deploy workflow for the low-level NFT example. |
| tokens/…/generate_merkle_tree.rs | Shows how a snapshot becomes a root and user-facing proof records. |
| tokens/…/sample-snapshot.json | Shows the source-to-Solana snapshot shape used by the tree generator. |
| tokens/…/lib.rs | Shows the airdrop setup, root update, proof check, vault transfer, and receipt flow. |
| tokens/…/README.md | Summarizes the distribution contract and the security properties expected from the flow. |