A gas-efficient token distribution system using Merkle tree-based claims with ECDSA signature support. Users can claim tokens by providing cryptographic proofs of eligibility, with optional meta-transaction support (allowing a gas-payer to submit claims on behalf of recipients).
Built with Foundry and designed for deployment on Ethereum and zkSync.
+------------------+
| BagelToken |
| (ERC20 + Ownable)|
+--------+---------+
|
| IERC20
v
+------------------+ +------------------+
| GenerateInput | | MerkleAirdrop |
| (script) +-->| (EIP712 + |
| | | MerkleProof + |
| MakeMerkle | | ECDSA) |
| (script) | +--------+---------+
+------------------+ |
| claim()
v
+------------------+
| DeployMerkle |
| Airdrop |
| (script) |
+------------------+
A simple ERC20 token with minting restricted to the contract owner.
- Symbol: BAGEL
- Access: Ownable
- Key Function:
mint(address to, uint256 amount)— owner-only minting
The core airdrop contract implementing Merkle tree-based claims with ECDSA signature verification.
- Inherits: EIP712
- Key Functions:
claim(address account, uint256 amount, bytes32[] calldata proof, uint8 v, bytes32 r, bytes32 s)— claim tokens with Merkle proof and signaturegetMessageHash(address account, uint256 amount)— returns the EIP-712 digestgetMerkleRoot()— returns the current Merkle rootgetAirdropToken()— returns the airdrop token address
- Events:
Claim(address indexed account, uint256 amount) - Custom Errors:
MerkleAirdrop__InvalidProof,MerkleAirdrop__InvalidSignature,MerkleAirdrop__AlreadyClaimed
# Clone the repository
git clone https://github.com/BuildsWithKing/merkle-airdrop.git
cd merkle-airdrop
# Install dependencies
forge install
# Copy and configure environment variables
cp .env.example .env
# Edit .env with your configuration| Variable | Description |
|---|---|
SEPOLIA_RPC_URL |
RPC URL for Sepolia testnet |
ETHERSCAN_API_KEY |
API key for Etherscan verification |
ZKSYNC_SEPOLIA_RPC_URL |
RPC URL for zkSync Sepolia |
| Command | Description |
|---|---|
make build |
Compile contracts |
make test |
Run tests |
make deploy |
Deploy to local/Sepolia |
make deploy-zk |
Deploy to zkSync local node |
make merkle |
Generate Merkle tree and proofs |
make sign |
Sign a claim message |
make claim |
Execute an airdrop claim |
make balance |
Check token balance |
make anvil |
Start Anvil local node |
make zktest |
Run tests with zkSync support |
make format |
Format Solidity code |
make clean |
Clean build artifacts |
Generate the Merkle root and proofs for whitelisted addresses:
make merkleThis runs GenerateInput.s.sol followed by MakeMerkle.s.sol, producing output in script/target/.
# Local
make deploy
# zkSync local node (requires Docker)
make deploy-zk# Sign the claim message
make sign
# Execute claim
make claimmake balance| Script | Purpose |
|---|---|
DeployMerkleAirdrop.s.sol |
Deploys BagelToken and MerkleAirdrop, funds the airdrop |
Interact.s.sol |
Claims tokens from the most recent deployment |
GenerateInput.s.sol |
Generates Merkle tree input from whitelisted addresses |
MakeMerkle.s.sol |
Computes Merkle root and proofs |
SplitSignature.s.sol |
Utility to split ECDSA signatures into v/r/s components |
# Standard tests
forge test
# Tests with zkSync support
make zktest| Library | Purpose |
|---|---|
| OpenZeppelin Contracts | ERC20, Ownable, MerkleProof, EIP712, ECDSA, SafeERC20 |
| forge-std | Foundry standard library for testing and scripting |
| murky | Merkle tree generation and proof computation |
| foundry-devops | Deployment utilities and zkSync chain detection |
^0.8.30
MIT