1/5
_Follow along with the video_ --- ### Introduction In this lesson we are going to build a script to handle the **signing** and **claiming** process. We will sign a message using an account that is _included in the Merkle tree_. This **signature** will allow another person to claim the airdrop on behalf of the original account. ### Setup We can begin by navigating into the `/script` folder and creating a `Interact.s.sol` file. To get the*most recently deployed airdrop contract*, we will use DevOps tools from Cyfrin foundry-devops, which should be already installed in this project. ```solidity import { Script, console } from "forge-std/Script.sol"; import { DevOpsTools } from "foundry-devops/src/DevOpsTools.sol"; import { MerkleAirdrop } from "../src/MerkleAirdrop.sol"; contract ClaimAirdrop is Script { function run() external { } } ``` Within the `run` function, we'll retrieve the most recently deployed `MerkleAirdrop` contract address and pass this contract address to a function `claimAirdrop`: ```solidity function run() external { address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment("MerkleAirdrop", block.chainid); claimAirdrop(mostRecentlyDeployed); } ``` ### `claimAirdrop` The `claimAirdrop` function will take the deployed `MerkleAirdrop` address as a parameter. First, we need to broadcast the transaction on the blockchain by wrapping our code between `vm.startBroadcast` and `vm.stopBroadcast`. Next, we invoke the `MerkleAirdrop::claim` function, passing the following required parameters: - **CLAIMING_ADDRESS**: The default Anvil key for the claiming address, which must be present in the Merkle Tree specified in the `input.json` file. This file can be regenerated by running the `GenerateInput` script. - **AMOUNT_TO_COLLECT**: Set to `25 * 1e18`. - **proof**: An array of bytes from the `output.json` file. - **v, r, s**: The components of the signature, which can be obtained either by: 1. Using `vm.sign(userPrivateKey, digest)`. 2. Using `cast wallet sign`. Here is the function: ```solidity function claimAirdrop(address airdrop) public { vm.startBroadcast(); // v, r, s are retrieved in the following lesson MerkleAirdrop(airdrop).claim(CLAIMING_ADDRESS, AMOUNT_TO_COLLECT, proof, v, r, s); vm.stopBroadcast(); } ```
Creating Interact.s.sol to claim the airdrop on Ethereum (or Anvil).
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at EigenLayer
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on March 26, 2025
Solidity Developer
Advanced FoundryDuration: 36min
Duration: 3h 06min
Duration: 5h 02min
Duration: 6h 02min
Duration: 2h 47min
Duration: 1h 23min
Duration: 4h 28min
Duration: 1h 19min
Duration: 1h 10min
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at EigenLayer
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on March 26, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar