This project demonstrates the creation of a Merkle tree-based airdrop system using Solidity and Hardhat.
-
Begin by installing the necessary dependencies:
npm install csv-parser keccak256 merkletreejs
-
Create your addresses.csv file in the following structure:
address,amount 0x123...abc,100 0x456...def,200
-
Execute the script with:
node merkle.js
-
Upon execution, the script will display the Merkle root and produce a
proofs.json
file.
-
Set up your Hardhat environment and configure your network settings.
-
Deploy the contract by running
npx hardhat run scripts/deploy.js --network network-name
Replace
network-name
with the network you are deploying to (e.g., localhost, sepolia, lisk, base, etc.). -
Ensure the deployment script passes the ERC20 token address and the Merkle root during deployment.
-
The merkle.js script generates a proofs.json file, containing the proofs needed for each address.
-
To claim tokens, users will require their address, the amount, and the relevant proof from the proofs.json file.
-
An example claim function call:
await MerkleAirdrop.claimAirdrop(proof, amount);
- Ensure that the Merkle root is generated from a reliable and trusted data source.
- The CSV file is assumed to be correctly formatted and to contain valid Ethereum addresses.
- The contract owner is responsible for ensuring the contract is funded with sufficient tokens before claims can be made.