How to Deploy Your Own ERC-20 Token with Ankr & Hardhat on ETH Goerli Testnet

·

By Krinza Momin


If the thought "I wish I had my own token" has ever crossed your mind, this guide will walk you through building and deploying your very own ERC-20 token on the Ethereum Goerli Testnet using Ankr’s Public RPCs and Hardhat.

What Is an ERC-20 Token?

ERC-20 tokens are the standard for fungible tokens on the Ethereum blockchain. They are:

Unlike NFTs (non-fungible tokens), ERC-20 tokens are interchangeable, making them ideal for currencies, rewards, and governance systems.


Step-by-Step Guide to Deploying Your Token

Step 1: Set Up MetaMask for Goerli Testnet

  1. Install the MetaMask extension.
  2. Select Goerli Testnet from the network dropdown.

Step 2: Acquire Goerli ETH

Step 3: Initialize Your Hardhat Project

  1. Create a project folder:

    mkdir erc20-token-ankr && cd erc20-token-ankr
    npm init -y
  2. Install Hardhat and dependencies:

    npm install --save-dev hardhat
    npx hardhat init  # Select "Create a sample project"
  3. Delete the default files (Greeter.sol and sample-script.js) in /contracts and /scripts.

Step 4: Configure Hardhat with Ankr’s RPC

  1. Install dotenv and ethers:

    npm install dotenv @nomiclabs/hardhat-ethers
  2. Add your MetaMask private key and Ankr’s Goerli RPC URL to .env:

    PRIVATE_KEY=YOUR_METAMASK_PRIVATE_KEY
    GOERLI_RPC_URL=https://rpc.ankr.com/eth_goerli
  3. Update hardhat.config.js:

    require("@nomiclabs/hardhat-ethers");
    require("dotenv").config();
    
    module.exports = {
      solidity: "0.8.0",
      networks: {
        goerli: {
          url: process.env.GOERLI_RPC_URL,
          accounts: [process.env.PRIVATE_KEY]
        }
      }
    };

Step 5: Create Your ERC-20 Token Contract

  1. Install OpenZeppelin’s contracts:

    npm install @openzeppelin/contracts
  2. Name your token (e.g., Buildoooor) and create a matching .sol file:

    touch contracts/Buildoooor.sol
  3. Paste this OpenZeppelin-based ERC-20 template:

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    
    contract Buildoooor is ERC20 {
        constructor(uint256 initialSupply) ERC20("Buildoooor", "BDR") {
            _mint(msg.sender, initialSupply);
        }
    }
  4. Compile the contract:

    npx hardhat compile

Step 6: Deploy to Goerli Testnet

  1. Create a deployment script:

    touch scripts/deploy.js
  2. Paste the deployment logic:

    async function main() {
      const [deployer] = await ethers.getSigners();
      console.log("Deploying contract with account:", deployer.address);
    
      const Token = await ethers.getContractFactory("Buildoooor");
      const token = await Token.deploy(1000000); // Mint 1M tokens
    
      console.log("Token deployed to:", token.address);
    }
    
    main().catch((error) => {
      console.error(error);
      process.exit(1);
    });
  3. Run the deploy command:

    npx hardhat run scripts/deploy.js --network goerli
  4. Verify your contract on Goerli Etherscan using the deployed address.

FAQs

1. Why Use Goerli Testnet?

Goerli allows you to test smart contracts without spending real ETH. It mimics Ethereum’s Mainnet environment.

2. How Do I Get More Goerli ETH?

Use faucets like Chainlink’s Goerli Faucet. Funds are replenished every 24 hours.

3. Can I Customize My Token’s Name/Symbol?

Yes! Edit the ERC20("Buildoooor", "BDR") line in your contract.

4. What’s Next After Deployment?

👉 Learn to create an ERC-721 NFT on Avalanche