Mode Docs
  • Introduction
    • 🟑Introducing Mode
    • βœ…AI Agent Dev Roadmap
  • AI AGENTS
    • Mode AI Terminal
    • 🀷What are AI Agents?
    • πŸ—οΈBuilding your first agent
    • Tutorials
      • Quickstart
    • πŸ› οΈAI Tooling
      • AI Audits
      • AI APIs
      • Frameworks
  • Tools
    • πŸ–₯️RPC
    • πŸͺΆMultisig wallets
    • πŸ”Bridge
    • 🚰Testnet Faucets
    • πŸ•΅οΈBlock Explorers
    • πŸ—‚οΈData Indexers
    • πŸ§™β€β™‚οΈOracles
    • ⛓️Interoperability
    • ⁉️Randomness
    • 🌎General Tooling
  • Tutorials
    • Interacting with Smart Contracts using ethers.js
    • Deploying a Smart Contract
      • Using Hardhat
      • Using Thirdweb
      • Using Foundry
      • Using Remix
    • Verifying your smart contract
      • Using Hardhat
      • Using Foundry
  • User Guides
    • ℹ️Network Details
    • 🦊Add Mode
    • 🏑Contract Addresses
      • Tokens
      • L1/L2 Mainnet Contracts
      • Testnet Contracts
    • πŸŒ‰Bridge
      • ➑️Bridge to Mode
      • ⬅️Bridge from Mode
      • πŸ—οΈBridging to Testnet
    • πŸ“€Move to/from CEX
  • $MODE
    • 🟑MODE Tokenonomics
    • 1️⃣Season 1 (ended)
    • 2️⃣Season 2 (ended)
    • 3️⃣Governance Season 3 (ended)
      • Governance Contract Addresses
    • 4️⃣Mode Governance Season 4
    • 5️⃣Season 5
  • Other Docs
    • πŸ”“General Security
      • πŸ”“Mode L2 Security Model
      • ⛑️Optimism Bug Bounty
      • Security Upgrades
        • 01/08/2024 Bridge Upgrade Fund Rescue
        • 06/08/2024 Mode Mainnet Key Handover
      • πŸ”Audits
    • πŸ”—Official Links
    • 🀘Branding Guidelines
    • ⌨️Node Operators
Powered by GitBook
On this page
  • Prerequisites
  • 1. Setting up the project
  • 2. Writing the ERC20 token contract
  • 3. Building the contract
  • 4. Deploying the ERC20 token contract
  • 5. Verifying the ERC20 token contract after deployment
  • 6. Exploring and interacting with your deployed contract

Was this helpful?

Edit on GitHub
  1. Tutorials
  2. Deploying a Smart Contract

Using Foundry

How to deploy with Foundry on Mode

PreviousUsing ThirdwebNextUsing Remix

Last updated 1 year ago

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.

Prerequisites

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, .

If you just want to skip to the build & deploy section of this tutorial, you can clone that contains a boilerplate Foundry project and skip to .

Let's get started!

1. Setting up the project

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:

forge init my-project

1.2. Install the OpenZeppelin contracts library inside your project, which provides a tested and community-audited implementation of ERC20:

forge install OpenZeppelin/openzeppelin-contracts

2. Writing the ERC20 token contract

2.1. In /src of your project directory, create a text file named MyERC20.sol and add:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

contract MyERC20 is ERC20 {
    constructor() ERC20("MyToken", "MTK") {}
}

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. Building the contract

3.1. Use Foundry to compile your smart contract running the following command:

forge build

4. Deploying the ERC20 token contract

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.

forge create --rpc-url https://sepolia.mode.network --private-key <YOUR_PRIVATE_KEY> src/MyERC20.sol:MyERC20

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.

forge create --rpc-url https://sepolia.mode.network --private-key <YOUR_PRIVATE_KEY> src/MyERC20.sol:MyERC20 --verify --verifier blockscout --verifier-url https://sepolia.explorer.mode.network/api\?

In the output you should get something like:

[β ’] Compiling... No files changed, compilation skipped 
Deployer: 0x3F26b51E23D01b09f4079B2a9e00e6873a8409D8 
Deployed to: 0x628F56856386A4De8414A4D8217D519bF94d03f0 
Transaction hash: 0xbe2d27554f130a720c4dd82dad055c941ca44dee836f6333a8507d76022c158

Copy the β€œDeployed to” value and store it somewhere to use later. This is the address of your contract.

5. Verifying the ERC20 token contract after deployment

5.1. For already deployed contracts you can use the verify-contract command:

forge verify-contract <CONTRACT_ADDRESS> src/MyERC20.sol:MyERC20  --verifier blockscout --verifier-url https://sepolia.explorer.mode.network/api\?

6. Exploring and interacting with your deployed contract

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 πŸ‘‹

blockscout
Discord
Foundry
how to bridge
this faucet
follow this guide
follow this guide
this repository
step 3