Skip to content

A secure and efficient token airdrop smart contract leveraging cryptographic proofs, EIP712 off-chain signatures, and ERC20 compatibility

Notifications You must be signed in to change notification settings

hedy-kh/AirDrop-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Merkle Airdrop

This project is a Solidity-based smart contract built with the Foundry framework. It enables the secure and efficient distribution of tokens to multiple recipients in a single transaction. The contract utilizes cryptographic proofs to verify recipient eligibility, ensuring that only authorized participants can claim tokens. This approach is inspired by established airdrop mechanisms used in blockchain ecosystems.


Getting Started

Requirements

Ensure you have the following installed:

This guide assumes you're working with standard Foundry, not Foundry-ZKSync.


Quickstart

Clone the repository and install dependencies:

git clone https://github.com/hedy-kh/AirDrop-Project.git
make  # or use "forge install && forge build" if you don't have make installed

Usage

Pre-deploy: Generate Merkle Proofs

To distribute tokens, we generate Merkle proofs for an array of recipient addresses. If you want to use the default addresses and proofs in this repository, skip to Deployment.

Generating New Merkle Proofs

  1. Update the list of addresses in GenerateInput.s.sol.
  2. Run the following command to generate the Merkle root and proofs:

Using make:

make merkle

Or manually:

forge script script/Generateinput.s.sol:GenerateInput && forge script script/MakeMerkle.s.sol:MakeMerkle
  1. Retrieve the Merkle root from script/target/output.json and update:
    • The ROOT variable in the Makefile (for zkSync deployments).
    • The s_merkleRoot in DeployMerkleAirdrop.s.sol (for Ethereum/Anvil deployments).

Deployment

Deploy to Anvil (Local Network)

# Ensure you're using standard Foundry
foundryup
# Start a local Anvil node
make anvil
# Deploy the contracts
make deploy

Interacting with the Contract (Local Anvil Network)

Setup Anvil & Deploy Contracts

foundryup
make anvil
make deploy

After deployment, copy the Airdrop Contract Address and Token Address, and paste them into the AIRDROP_ADDRESS and TOKEN_ADDRESS variables in the Makefile.

Signing the Airdrop Claim

make sign

Retrieve the generated signature and update Interact.s.sol.
If you've changed the recipient addresses in the Merkle tree, also update the proof data from output.json.

Claiming the Airdrop

make claim

Checking Claim Amount

Verify the claim by checking the balance:

make balance

The default Anvil address (0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266) will receive the airdropped tokens.


Testing

Run tests using Foundry:

foundryup
forge test

For zkSync compatibility:

make zktest  # Runs: foundryup-zksync && forge test --zksync && foundryup

Test Coverage

forge coverage

Gas Estimation

Estimate gas costs with:

forge snapshot

Results will be stored in .gas-snapshot.


Code Formatting

Ensure consistent formatting:

forge fmt

Conclusion

This project provides a secure and efficient way to distribute tokens using cryptographic proofs. By leveraging Foundry, ensure a robust testing and deployment process.

About

A secure and efficient token airdrop smart contract leveraging cryptographic proofs, EIP712 off-chain signatures, and ERC20 compatibility

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published