Token Faucet
Rate-limited token distribution faucet with cooldown periods
Deployed
Anchor 0.32
Program ID
GsHPNhJtQ23Nj2duABZNDAdn1ri2kjxkeTXqH6SUSN1v
Repository
ExpertVagabond/solana-token-faucet
Binary Size
286K
Cluster
Devnet
Instructions
IX
initialize_faucet
Creates a new token faucet with a configurable distribution amount and cooldown period.
| Parameter | Type | Description |
|---|---|---|
amount_per_claim | u64 | Number of tokens distributed per claim |
cooldown | i64 | Cooldown period in seconds between claims per wallet |
IX
claim
Claims tokens from the faucet. Enforces the per-wallet cooldown period.
| Parameter | Type | Description |
|---|---|---|
| No parameters | ||
IX
fund
Deposits additional tokens into the faucet vault to replenish supply.
| Parameter | Type | Description |
|---|---|---|
amount | u64 | Number of tokens to deposit |
IX
update_config
Updates the faucet configuration. Only callable by the authority.
| Parameter | Type | Description |
|---|---|---|
amount_per_claim | u64 | New distribution amount per claim |
cooldown | i64 | New cooldown period in seconds |
Accounts
Faucet
| Field | Type | Description |
|---|---|---|
authority | Pubkey | Faucet creator and admin |
mint | Pubkey | Token mint distributed by the faucet |
amount_per_claim | u64 | Tokens given per claim |
cooldown | i64 | Minimum seconds between claims per wallet |
total_claims | u64 | Total number of claims made |
bump | u8 | PDA bump seed |
ClaimRecord
| Field | Type | Description |
|---|---|---|
faucet | Pubkey | The faucet this record tracks |
claimer | Pubkey | Wallet address of the claimer |
last_claim | i64 | Timestamp of the most recent claim |
total_claimed | u64 | Total tokens claimed by this wallet |
bump | u8 | PDA bump seed |
PDA Derivation
faucet
seeds = [b"faucet", authority, mint]
claim
seeds = [b"claim", faucet, claimer]
vault
seeds = [b"vault", faucet]
Error Codes
CooldownNotExpired
Must wait for the cooldown period to elapse before claiming again
Overflow
Arithmetic overflow in claim tracking
Usage Example
import { Program, BN } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; // Derive PDAs const [faucetPda] = PublicKey.findProgramAddressSync( [Buffer.from("faucet"), authority.publicKey.toBuffer(), mint.toBuffer()], program.programId ); const [claimPda] = PublicKey.findProgramAddressSync( [Buffer.from("claim"), faucetPda.toBuffer(), claimer.publicKey.toBuffer()], program.programId ); // Initialize faucet: 100 tokens per claim, 1 hour cooldown await program.methods .initializeFaucet(new BN(100_000_000), new BN(3600)) .accounts({ faucet: faucetPda, authority: authority.publicKey, mint, }) .signers([authority]) .rpc(); // Claim tokens await program.methods .claim() .accounts({ faucet: faucetPda, claimRecord: claimPda, claimer: claimer.publicKey, mint, }) .signers([claimer]) .rpc();