1/5
_Follow along with the video_ --- To deploy the `BagelToken` and `MerkleAirdrop` contracts, we can follow a structured approach by creating a **deployment script**. ### `deployMerkleAirdrop` Function Inside the `script` directory, we can start coding the deployment contract by importing the required libraries: ```js // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import {MerkleAirdrop} from "src/MerkleAirdrop.sol"; import {BagelToken} from "src/BagelToken.sol"; import {Script} from "forge-std/Script.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; ``` Next, create the deployment function to deploy the contracts, mint tokens, and transfer them to the airdrop contract: ```js function deployMerkleAirdrop() public returns (MerkleAirdrop, BagelToken) { vm.startBroadcast(); BagelToken bagelToken = new BagelToken(); MerkleAirdrop airdrop = new MerkleAirdrop(ROOT, IERC20(bagelToken)); bagelToken.mint(bagelToken.owner(), AMOUNT_TO_TRANSFER); // amount for four claimers IERC20(bagelToken).transfer(address(airdrop), AMOUNT_TO_TRANSFER); // transfer tokens to the airdrop contract vm.stopBroadcast(); return (airdrop, bagelToken); } ``` ### Test Environment Setup To retrieve and use the last deployed contract in our `MerkleAirdrop.t.sol` file, install `foundry-devops` with the command: ```bash forge install cyfrin/foundry-devops --no-commit ``` Then, in the `setUp` function, add a check to determine if the current chain is ZKsync: ```js //.. import {ZkSyncChainChecker} from "foundry-devops/src/ZkSyncChainChecker.sol"; function setUp() public { if (!isZkSyncChain()) { //chain verification DeployMerkleAirdrop deployer = new DeployMerkleAirdrop(); (airdrop, token) = deployer.deployMerkleAirdrop(); } else { token = new BagelToken(); airdrop = new MerkleAirdrop(merkleRoot, token); token.mint(token.owner(), amountToSend); token.transfer(address(airdrop), amountToSend); } (user, userPrivKey) = makeAddrAndKey("user"); } ``` The `zkSyncChainChecker` determines if we are currently on a ZKsync chain. If we are not, we deploy the contracts using our script and proceed with testing. Otherwise, we directly deploy new instances of the `BagelToken` and `MerkleAirdrop` contracts, mint the necessary tokens to the contract owner, and transfer the required amount of tokens to the `MerkleAirdrop` contract.
Creating a deployment script to deploy both the token contract and the airdrop contract.
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 Avara
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on November 29, 2024
Solidity Developer
Advanced FoundryDuration: 36min
Duration: 3h 06min
Duration: 5h 02min
Duration: 2h 47min
Duration: 1h 23min
Duration: 4h 28min
Duration: 1h 19min
Duration: 58min
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 Avara
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on November 29, 2024
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