Deploy an ERC-20 Token
Last updated
Was this helpful?
Last updated
Was this helpful?
This tutorial guides you through deploying an ERC-20 token using , a comprehensive Ethereum development environment. Hardhat is recommended for its powerful features, but you can also use other Ethereum development tools like .
Ensure Node.js, Hardhat, and Solidity are set up correctly for effective ERC-20 token development and deployment.
Earn and track Hemi for completing this tutorial!
Download (or any other IDE)
Install or update it to
Create a folder on your computer and name it TestToken
.
This folder will serve as your project directory, containing all the elements and code needed to deploy your ERC-20 token.
In your TestToken
project directory, open a terminal window and initialize a Node.js project
Install Hardhat along with the Ether.js plugin, and the OpenZeppelin contracts library.
a) Inside your Node.js project, start a Hardhat project
b) Select Create an empty hardhat.config.js
In the root directory of your project, create contracts
and scripts
folders:
In the contracts
folder, create a file named MyToken.sol
. This will be your ERC-20 token contract. Here's a basic example:
This code defines a simple ERC-20 token with an initial supply and basic ERC-20 functionalities.
Your private key provides access to your wallet and your funds. Never share your private key with anyone. Ensure this file is never shared or committed to version control.
a) Export your private key from MetaMask:
Open MetaMask, select your account icon, and go to Account Details
Select Show private key
Enter your password.
Select Confirm
Select the unlock button to reveal your password.
b) Install dotenv
package
c) Run the command touch .env
to create an .env
file in the root directory of your project.
d) Run the command nano .env
to open the CLI editor
e) Add your private key to the .env
file.
a) Open hardhat.config.js
in your project.
b) Configure Hemi Network
Add the required modules at the top of the config file
Add the Hemi Network settings inmodule.exports
. Ensure you include the network's URL, Chain ID, and the accounts array with your private key (stored in an environment variable for security).
Here's an example configuration:
In the scripts
folder, create a file named deploy.js
to write a script for deploying your contract.
This script is deploying MyToken
with an initial supply (customize the supply as needed).
Contract details we just deployed:
To view the details of your deployed contract, enter the contract address from your success message into the . This will provide you with information about the contract's transactions and state.