Deploy an ERC-20 Token
📜 TL;DR:
Ensure Node.js, Hardhat, and Solidity are set up correctly for effective ERC-20 token development and deployment.
Earn and track Hemi points for completing this tutorial!
🏁 Prerequisites
Download VSCode (or any other IDE)
Install Node.js or update it to current version
📚 Tutorial
Video
1. Create A Project Directory
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.
2. Initialize Your NPM Project
In your
TestToken
project directory, open a terminal window and initialize a Node.js project
3. Install Hardhat & Ethers.js Plugin
Install Hardhat along with the Ether.js plugin, and the OpenZeppelin contracts library.
4. Create a HardHat Project
a) Inside your Node.js project, start a Hardhat project
b) Select Create an empty hardhat.config.js
5. Add Folder
In the root directory of your project, create contracts
and scripts
folders:
6. Write Your Contract
In the
contracts
folder, create a file namedMyToken.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.
7. Compile Your Contract
8. Secure Your Private Key for Deployment
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.
Ensure this file is never shared or committed to version control.
9. Configure Hardhat for the Testnet
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 in
module.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:
10. Write a Deployment Script
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).
11. Deploy the Contract
If the deployment is successful, you will see messages indicating the token was deployed to
Token deployed to: 0x5fc5c2265E4f77E63e82f7F10FE803d04Cc53D82
To view the details of your deployed contract, enter the contract address from your success message into the Hemi Testnet explorer. This will provide you with information about the contract's transactions and state.
Contract details we just deployed:
Last updated