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:
- Fungible: Each token is identical in value and function.
- Transferable: Tokens can be sent between wallets seamlessly.
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
- Install the MetaMask extension.
- Select Goerli Testnet from the network dropdown.
Step 2: Acquire Goerli ETH
- Visit the Goerli Faucet, connect your MetaMask wallet, and request test ETH.
- Note: Testnet ETH has no real-world value.
Step 3: Initialize Your Hardhat Project
Create a project folder:
mkdir erc20-token-ankr && cd erc20-token-ankr npm init -yInstall Hardhat and dependencies:
npm install --save-dev hardhat npx hardhat init # Select "Create a sample project"- Delete the default files (
Greeter.solandsample-script.js) in/contractsand/scripts.
Step 4: Configure Hardhat with Ankr’s RPC
Install
dotenvandethers:npm install dotenv @nomiclabs/hardhat-ethersAdd 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_goerliUpdate
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
Install OpenZeppelin’s contracts:
npm install @openzeppelin/contractsName your token (e.g.,
Buildoooor) and create a matching.solfile:touch contracts/Buildoooor.solPaste 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); } }Compile the contract:
npx hardhat compile
Step 6: Deploy to Goerli Testnet
Create a deployment script:
touch scripts/deploy.jsPaste 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); });Run the deploy command:
npx hardhat run scripts/deploy.js --network goerli- 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