How to Create an ERC-20 Token (4 Steps) (2024)

An Ethereum Token is an incredibly powerful feature of the Ethereum virtual machine, as it can represent virtually anything from financial assets to skills of a game character, to a fiat currency, and so much more.

  • Why build your Own ERC-20 token?
  • What is ERC-20?
  • How to create your own ERC-20 tokens

Why build your own ERC-20 token?

The ERC-20 token standard is the most popular way to create fungible cryptocurrencies on Ethereum and EVM-compatible blockchains, and therefore allows builders and creators to develop digital assets for their protocol, marketplace, metaverse, or community.

This tutorial will teach you how to create your own ERC-20 token on Ethereum’s Goerli testnet using Alchemy, MetaMask, HardHat, and Solidity code snippets. At the end of this tutorial, you will be able to deploy your own ERC-20 token smart contract. The estimated time to complete this guide is 15 minutes.

The ERC-20 token standard ensures that all tokens have the same properties, including that all tokens are fungible (any one token is exactly equal to any other token), and no tokens have special properties or rights associated with them.

This means that for a token to follow the ERC-20 token standard, it must implement the following API methods and events:

  • totalSupply - a method that defines the total supply of your tokens, and stops creating new tokens when the totalSupply limit is reached.
  • balanceOf - a method that returns the number of tokens a wallet address contains.
  • transfer - a method that transfers in a certain amount of tokens from the total supply and sends it to a user.
  • transferFrom - a transfer method that transfers ERC-20 tokens between users
  • approve - verifies whether a smart contract is allowed to allocate a certain amount of tokens to a user, considering the total supply.
  • allowance - checks if a user has enough balance to send a token to another user.

ERC-20 tokens are fungible (can be interchanged) because they have the same value and properties. There are also non-fungible token standards and semi-fungible token standards such as ERC-721 and ERC-1155 tokens.

In four steps you’ll create and deploy an ERC-20 token on the Goerli test network, using Metamask, Solidity, Hardhat, and Alchemy. This Goerli ERC-20 token will have all the characteristics required above, making it a valid ERC-20 token.

🚧

Choosing a testnet

While you can use the Goerli testnet, we caution against it as the Ethereum Foundation has announced that Goerli will soon be deprecated.

We therefore recommend using Sepolia testnet as Alchemy has full Sepolia support and a free Sepolia faucet also.

First, create an Alchemy account, and set up Metamask, HardHat, and Solidity for this project. For a walkthrough, read through the ChainShot HardHat guide.

Next, enter mk my-token and cd my-token to create a folder for your project and change directories to your my-token folder, then run npm init

If you don't already have NPM installed, use this developer environment setup guide.

mk my-tokencd my-tokennpm init

Next, go to the my-token project root directory and type mkdir contracts and mkdir scripts into your command line to create two new folders that will organize your ERC-20 smart contracts and your deployment scripts:

mkdir contractsmkdir scripts

2. Write ERC-20 Token Smart Contract

Here’s how to write the token contract for your ERC-20 token using Solidity, which is like Java and JavaScript, or C and C++:

  1. Open up the my-token project in your code editor.
  2. Navigate to your /contracts folder
  3. Open a new .sol file and name the .sol file the same name as your token.
    Note: To create and work with your smart contract file, you must have a name that matches the name of your token. For example, to create a token named Web3Token, your contract file name should be Web3Token.sol.

Copy and paste this code snippet based on the OpenZeppelin ERC 20 implementation:

//SPDX-License-Identifier: Unlicensepragma solidity ^0.8.0;import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; // OpenZeppelin package contains implementation of the ERC 20 standard, which our NFT smart contract will inheritcontract GoofyGoober is ERC20 { uint constant _initial_supply = 100 * (10**18); // setting variable for how many of your own tokens are initially put into your wallet, feel free to edit the first number but make sure to leave the second number because we want to make sure our supply has 18 decimals /* ERC 20 constructor takes in 2 strings, feel free to change the first string to the name of your token name, and the second string to the corresponding symbol for your custom token name */ constructor() ERC20("GoofyGoober", "GG") public { _mint(msg.sender, _initial_supply); }}

The token symbol you choose, in our case "GG" can be any arbitrary character length but do keep in mind that some UIs may display ones that are too long differently.
Feel free to edit the initial supply by changing the 100 to how many tokens you would like your initial supply to be - we put 100 because there are very few true Goofy Goobers in the world! You can put any number you'd like for this - make sure to leave the (10**18) as that multiplies the number we want as our supply to have 18 decimals.

Now that your token contract is written, write your smart contract deployment script by:

  1. Navigating to the /scripts folder
  2. Creating a new file called deploy.js
  3. Opening the deploy.js file
  4. Copying and pasting this ERC-20 deployment code snippet:
async function main() { const [deployer] = await ethers.getSigners(); console.log("Deploying contracts with the account:", deployer.address); const weiAmount = (await deployer.getBalance()).toString(); console.log("Account balance:", (await ethers.utils.formatEther(weiAmount))); // make sure to replace the "GoofyGoober" reference with your own ERC-20 name! const Token = await ethers.getContractFactory("GoofyGoober"); const token = await Token.deploy(); console.log("Token address:", token.address);}main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1);});

4. Deploy your ERC-20 Token to Goerli

To deploy your ERC-20 token, navigate to your root directory and run the following command:

npx hardhat run scripts/deploy.js --network goerli

Your contract will be compiled and deployed to the Goerli network! You should see a message appear with information about the smart contracts you are deploying including your account address, account balance, and token address.

Go to https://goerli.etherscan.io/ and input your outputted Token address to see your deployed ERC-20 contract on Goerli!

Now it's time to have real fun! Send some of your new tokens to your friends and family, stimulate an economy - create the Bitcoin/Ethereum of the future! In this guide, you deployed your own ERC-20 token on Goerli using the OpenZeppelin ERC20 standard - great job!

We are going to challenge you to send some tokens in one of two ways:

  1. More Challenging Way: Write your own Hardhat Script to do an airdrop!
  2. Simpler Way: Add your ERC-20 token to MetaMask and send it to an address via the UI!

Related Tutorials

  • How to Get ERC-20 Token Balance at a Given Block
  • How to Interact with ERC-20 tokens in Solidity
  • How to Send ERC20 Tokens in an EIP-1559 Transaction

Updated about 1 year ago

How to Create an ERC-20 Token (4 Steps) (2024)

FAQs

How to Create an ERC-20 Token (4 Steps)? ›

On average, the cost to create ERC20 token lies between $5000 to $10,000, depending on the type of token developed and business requirements.

How do you create a token step by step? ›

You can create your ERC20 token using the following five steps.
  1. Token specifications. The first step is related to the specifications of the token. ...
  2. Codification of the contract. ...
  3. Testing the token on a testnet. ...
  4. Verify the token source code.

How much does it cost to create an ERC20 token? ›

On average, the cost to create ERC20 token lies between $5000 to $10,000, depending on the type of token developed and business requirements.

How to create an ERC20 token? ›

How to Create an ERC-20 Token
  1. Set Up your Developer Environment. First, create an Alchemy account, and set up Metamask, HardHat, and Solidity for this project. ...
  2. Write ERC-20 Token Smart Contract. ...
  3. Write a Deployment Script for your ERC-20 Token. ...
  4. Deploy your ERC-20 Token to Goerli. ...
  5. Step 4: Send Some Tokens!

Can I create my own crypto token? ›

Can I Create My Own Cryptocurrency? You can make your own cryptocurrency. Usually creating a new coin or token requires some computer coding expertise, but you also can choose to hire a blockchain developer to create a digital currency for you.

How do I manually add an ERC20? ›

Add your token manually by contract

First, go to the Wallet tab and click the "+" icon at the top-right corner. Now, you can either add your token manually by its contract or simply send it to your ETH address.

What is the best crypto token generator? ›

If you want to create your crypto tokens then you should use the finest token generator platforms such as Cointool. App, Togen.io, and Tokenmint.

Can I create a token for free? ›

The short answer is yes! If you don't have any coding or technical knowledge, then using a token generator such as Token Tool is the perfect solution.

How much does it cost to mint an ERC-20 token? ›

Basic ERC20 tokens typically handle basic functions such as money transfer and storage. Simple estimates to create a basic ERC20 token fall between $5,000 and $10,000. These costs include token creation, development, testing, and implementation.

How much is 50 ERC20 in dollars? ›

ERC20 to USD
AmountToday at 1:39 am
1 ERC20$0.0038
5 ERC20$0.0189
10 ERC20$0.0378
50 ERC20$0.1890
4 more rows

How much gas does it take to send ERC20 tokens? ›

If you're sending ERC20 to your friend, you'll need around 65,000 gas (and 21000 for ETH) for the transaction at the moment. But if you want to seal the deal on Uniswap, your estimated gas limit would go up to 200,000. The gas limit refers to the maximum amount of gas users would use for a transaction.

Can you mine ERC-20 tokens? ›

Is It Possible to Mine ERC-20 Tokens? While you can mine Ethereum's native currency, ETH, the process for creating ERC-20 tokens is different; they are minted, not mined.

How many ERC20 tokens exist? ›

ERC-20 tokens are custom user cryptocurrencies created on Ethereum, based on the successful ERC-20 Token Standard. Currently, there are over 500,000 ERC-20 tokens in existence, most of which have no market value. See the full list here.

Is it hard to create a meme coin? ›

But it's also a venture with its own set of difficulties. Making a meme coin is not an easy task, involving everything from the technical aspects of blockchain and smart contract development to the intricacies of tokenomics, community building, and navigating a constantly changing regulatory landscape.

How are tokens created? ›

Smart contract development: Tokens are created through smart contracts, which are self-executing contracts with the terms of the agreement directly written into code. Developers write smart contracts using programming languages like Solidity (for Ethereum) or Vyper.

How do I create a custom token? ›

Custom tokens are typically created within custom modules, which offer a structured way to extend Drupal's functionality without altering core files.
  1. Create a Custom Module Directory. Navigate to the module directory of your Drupal installation. ...
  2. Define Module Metadata. ...
  3. Implement Token Functions. ...
  4. Clear Drupal's Cache.
Apr 29, 2024

How do I create an access token? ›

How to get an access token
  1. Create a developer account and retrieve your client_id and client_secret.
  2. Your client is allowed to use the following scopes (verifiable under App settings): authorization:grant user:create user:read accounts:read transactions:read credentials:read.

Top Articles
Futures Commission Merchant (FCM): Definition, Role, Registration
Tomb Murals of the Four Guardian Deities from Gangseojungmyo | Current Exhibitions
Scheelzien, volwassenen - Alrijne Ziekenhuis
Omega Pizza-Roast Beef -Seafood Middleton Menu
What Are Romance Scams and How to Avoid Them
Gunshots, panic and then fury - BBC correspondent's account of Trump shooting
Optum Medicare Support
Chase Claypool Pfr
Fallout 4 Pipboy Upgrades
Texas (TX) Powerball - Winning Numbers & Results
Tugboat Information
Catsweb Tx State
Craigslist Dog Kennels For Sale
David Turner Evangelist Net Worth
Hell's Kitchen Valley Center Photos Menu
Craigslist Blackshear Ga
Images of CGC-graded Comic Books Now Available Using the CGC Certification Verification Tool
Harem In Another World F95
Delaware Skip The Games
Program Logistics and Property Manager - Baghdad, Iraq
Iroquois Amphitheater Louisville Ky Seating Chart
SuperPay.Me Review 2023 | Legitimate and user-friendly
Imouto Wa Gal Kawaii - Episode 2
Living Shard Calamity
The Creator Showtimes Near R/C Gateway Theater 8
Mineral Wells Skyward
Buhl Park Summer Concert Series 2023 Schedule
What we lost when Craigslist shut down its personals section
Ryujinx Firmware 15
Craigslistodessa
Kaiserhrconnect
Lowell Car Accident Lawyer Kiley Law Group
Supermarkt Amsterdam - Openingstijden, Folder met alle Aanbiedingen
Go Smiles Herndon Reviews
20+ Best Things To Do In Oceanside California
Midsouthshooters Supply
Snohomish Hairmasters
Ludvigsen Mortuary Fremont Nebraska
Gold Dipping Vat Terraria
Anguilla Forum Tripadvisor
Wunderground Orlando
Autum Catholic Store
Funkin' on the Heights
Tyco Forums
Underground Weather Tropical
1990 cold case: Who killed Cheryl Henry and Andy Atkinson on Lovers Lane in west Houston?
Online TikTok Voice Generator | Accurate & Realistic
Msatlantathickdream
Campaign Blacksmith Bench
Where and How to Watch Sound of Freedom | Angel Studios
Free Carnival-themed Google Slides & PowerPoint templates
Congressional hopeful Aisha Mills sees district as an economical model
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 6021

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.