Avascan Knowledge Base
  • Get started
  • 📗How to use Avascan
    • Introduction
    • Homepage
    • Unified Transaction List
    • Blocks
    • Assets
    • Token page
    • Verified contracts
    • Marketcap
    • Network Activity
    • Avalanche Bridge
    • Transaction Details
    • Blockchains
    • X-Chain
    • C-Chain
    • Staking
    • Whale Transactions
    • Rich List
    • Hot dApps
    • Burned Fees
    • AVAX Genesis
    • Avalanche Market Cap
    • Keyboard shortcuts
    • Universal Search v0.1
    • Metamask configuration
  • Delegation
    • How to delegate
    • FAQs
    • How to choose a validator
    • Avascan validators
  • 🌟Programs
    • Validator Claim
    • Asset Claim
    • Address Claim
    • The Blue Badge
  • 👩‍💻Tutorial
    • How to verify smart contract
    • How to setup your token marketcap
    • Deploy and verify an ERC-20 token
  • 📖APIs
    • Documentation
    • /api/v1 (deprecated)
      • Supply (deprecated)
      • Statistics (deprecated)
      • Staking (deprecated)
      • Burned fees (deprecated)
      • GraphQL (deprecated)
    • /api/v2
Powered by GitBook
On this page
  • Step 1
  • Step 2
  • Step 3
  • Step 4

Was this helpful?

  1. Tutorial

Deploy and verify an ERC-20 token

Step 1

First we’re going to create a new folder and install hardhat:

$ mkdir mock-token$ cd mock-token
$ npm init
$ npm install --save-dev hardhat

Now let’s bootstrap a hardhat project. Select the option "Create an empty hardhat.config.js":

$ npx hardhat 

Let’s also create a couple of folders for our files:

$ mkdir scripts contracts

Now install some dependencies to our project:

$ npm install --save-dev @nomiclabs/hardhat-ethers ethers @nomiclabs/hardhat-waffle ethereum-waffle chai
$ npm install --save-dev @nomiclabs/hardhat-etherscan

Step 2

Let’s now create a first Solidity contract at contracts/Token.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
 
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
 
contract MockToken is ERC20 {
    constructor() ERC20("Mock Token", "Mock") {
        _mint(msg.sender, 1000000 * 10**decimals());
    }
}

We need to install openzeppelin library to our file:

$ npm install @openzeppelin/contracts

Try to compile the contract with:

$ npx hardhat compile

Step 3

We should prepare our hardhat.config.js file as:

require("@nomiclabs/hardhat-etherscan");
require("@nomiclabs/hardhat-waffle");
 
const PRIVATE_KEY = "PRIVATEKEY";
 
module.exports = {
    solidity: "0.8.2",
    defaultNetwork: "fuji",
    networks: {
      mainnet: {
        url: `https://api.avax.network/ext/bc/C/rpc`,
        accounts: [PRIVATE_KEY]
      },
      fuji: {
        url: `https://api.avax-test.network/ext/bc/C/rpc`,
        accounts: [PRIVATE_KEY]
      }
    },
    etherscan: {
      apiKey: {
        fuji: "avascan" // apiKey is not required, just set a placeholder
      },
      customChains: [
        {
          network: "fuji",
          chainId: 43113,
          urls: {
            apiURL: "https://api.avascan.info/v2/network/testnet/evm/43113/etherscan",
            browserURL: "https://testnet.avascan.info/blockchain/c"
          }
        }
      ]
    },
};

Step 4

Now let’s add the deploy script. To keep it simple we’ll simply reuse the deploy script from the Hardhat tutorial, so let’s create the file scripts/deploy.js:

const { ethers } = require("hardhat");
 
async function main() {
    const [deployer] = await ethers.getSigners();
 
    const Token = await ethers.getContractFactory("MockToken");
    const token = await Token.deploy();
    console.log("Contract address:", token.address);
}
 
main()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error(error);
        process.exit(1);
    });

After wrote our script, we can call deploy file:

$ npx hardhat run scripts/deploy.js --network fuji
$ npx hardhat verify --contract contracts/Token.sol:MockToken --network fuji <contractaddress>
PreviousHow to setup your token marketcapNextDocumentation

Last updated 2 years ago

Was this helpful?

👩‍💻