Using Foundry
How to deploy with Foundry on Mode
Last updated
Was this helpful?
How to deploy with Foundry on Mode
Last updated
Was this helpful?
This guide will walk you through the deployment of an ERC20 token on MODE using . Foundry is a smart contract development toolchain written in Rust.
Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts.
Given that MODE is built on the OP Stack and is EVM-compatible, you can easily port any Ethereum-based smart contract without modifying the core code, requiring only minor setting adjustments.
Even if you need to do these 3 steps, it wonβt take more than 10 minutes to set up:
Have some ETH on Mode Testnet Network. You can follow our guide on . Or use to claim some ETH on Mode.
Rust must be installed on your computer. If it's not, .
Foundry must be installed on your computer. If itβs not, .
Let's get started!
1.1 Initialize a new Foundry project:
Forge is the command-line interface (CLI) tool for Foundry, allowing developers to execute operations directly from the terminal.
Open up a terminal and run this command:
1.2. Install the OpenZeppelin contracts library inside your project, which provides a tested and community-audited implementation of ERC20:
2.1. In /src of your project directory, create a text file named MyERC20.sol and add:
This is a simple ERC20 token named "MyToken" with the symbol "MTK". You can name it any way you want and also write any other contracts. Just remember that if your file name is called differently, the commands to deploy will be slightly different.
This is what you should have up to now:
3.1. Use Foundry to compile your smart contract running the following command:
4.1. To deploy your contract you will need to run the following command and replace <YOUR_PRIVATE_KEY> with your credentials:
Never share or expose your private key publicly. This will grant complete control to whoever has it. Please store it safely.
PRO TIP: You can add the --verify flag and use blockscout to verify your contract while deploying.
The following is the command to deploy and verify the contract. If you already deployed your contract but still want to verify it, don't panic! Next step will walk you through that case.
In the output you should get something like:
Copy the βDeployed toβ value and store it somewhere to use later. This is the address of your contract.
5.1. For already deployed contracts you can use the verify-contract command:
In the "Contract" tab you'll find your verified contract.
Congratulations, you just deployed and verified a contract on Mode Network using Foundry.
If you want the next challenge, you can try registering a contract for the SFS following this guide: SFS - Registering a contract with Remix
Use the explorer to view your contract's details. Paste your contract's address you saved from the deployment output into blockscout's search bar.
To learn more about Mode and how to turn your code into a business, join our and say hello π