Ethernity Layer 2
  • Introduction
    • 🌎Introducing Ethernity Chain
    • ℹ️General Information
    • πŸ’³Connect your wallet
    • πŸ‘©β€πŸ’»Network Information
  • ERN TOKEN
    • πŸͺ™ERN Tokenomics
    • πŸ₯‡Privileges for ERN Holders
  • DEFI PRODUCTS
    • 🎯Fixed Staking
    • πŸ€‘Satoshi Staking
    • πŸ’ŽStones Farming
  • GOVERNANCE
    • πŸ›οΈDAO
  • DRM
    • 🧠Introduction
    • ❓How it works
    • πŸ’―Authenticity Confidence
    • ℒ️Protected brands/licenses
    • ➑️Add your Collection
  • DEVELOPER TOOLS
    • πŸ’»Network Information
    • πŸ“”Addresses
    • πŸ—‚οΈIndexers
    • πŸ’³Wallets
  • TUTORIALS
    • Deploy a Smart Contract
      • With Hardhat
      • With Foundry
      • With Remix
    • βœ…Verify a Smart Contract
    • πŸ’°Create an ERC-20 token
    • πŸ‘·Create an NFT Collection
  • SECURITY
    • πŸ”ŽAudits
    • 🎁Bug Bounty
  • OTHER
    • πŸ§‘β€πŸ€β€πŸ§‘Community
    • πŸ“šMedia Kit
    • πŸ”Privacy Policy
    • πŸ“„Terms of Service
Powered by GitBook
On this page
  • Prerequisites
  • 1. Set up the project
  • 2. Write the ERC20 token contract
  • 3. Build the contract
  • 4. Deploy the ERC20 token contract
  • 5. Verify the contract
  • 6. Exploring and interacting with your deployed contract

Was this helpful?

  1. TUTORIALS
  2. Deploy a Smart Contract

With Foundry

Prerequisites

  • ETH on Ethernity:

  • Rust:

  • Foundry:

1. Set 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. Write 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.

3. Build the contract

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

forge build

4. Deploy 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://testnet.ethernitychain.io --private-key <YOUR_PRIVATE_KEY> src/MyERC20.sol:MyERC20

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://testnet.ethernitychain.io --private-key <YOUR_PRIVATE_KEY> src/MyERC20.sol:MyERC20 --verify --verifier blockscout --verifier-url https://sepolia.explorer.mode.network/api\?

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

5. Verify the contract

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

PreviousWith HardhatNextWith Remix

Last updated 11 months ago

Was this helpful?

Use to view your contract's details. Paste your contract's address you saved from the deployment output into blockscout's search bar.

ERNScan