Create an ERC-20 token
Last updated
Was this helpful?
Last updated
Was this helpful?
Creating an ERC-20 token steps are pretty much the same steps as deploying a smart contract, the only difference is the contract code. You will be able to create an ERC-20 token that can be a memecoin, an utility cryptocurrency, a social token, etc. Let's go over the steps with the Hardhat example and using battle-tested :
Requirements
Node.js and npm: download and install both packages
Ethereum Wallet: or any other non-custodial Ethereum wallet, since you will need the
ETH: You can get some and then bridge it to Ethernity
Solidity and CLI knowledge
Open your terminal and create a new directory for your project, then navigate into it:
Initialize an npm project:
Install the necessary packages for Hardhat, TypeScript and Open Zeppelin:
Start a new Hardhat project with TypeScript:
When prompted, make the following selections:
Choose "Create a TypeScript project".
For the .gitignore
prompt, select "Yes" (or y
).
For installing the projects dependencies select "Yes" (or y
).
In the contracts
directory, delete the sample smart contract Lock.sol
and then create a new file named Token.sol.
For a fixed supply, standard ERC-20 token that will mint the entire initial supply to your wallet, use this code for the Token.sol file:
The standard is 18 decimal places - if you want to create a token with a different decimals setting, add this function above contract Token ...
:
and replace the 16 with whatever decimal places you want (not recommended though, better to have the standard of 18).
Although not recommended, you can deploy a mintable token by exposing the standard _mint function:
Then only the owner (the wallet that deployed the contract) will get the initial supply, and will be able to mint more.
Edit the hardhat.config.ts
file to include Ethernity Chain Testnet settings:
Replace PRIVATE_KEY
with your Ethereum wallet private key.
IMPORTANT: Do not push your hardhat.config.ts
file to github or share your private key with anyone.
Compile the smart contract:
In the scripts
directory, create a new file named deploy.ts
:
Now you can deploy the smart contract to Ethernity Testnet:
Follow to verify the token contract.
See your brand new Token deployed on the Ethernity Testnet block explorer (ERNScan): . Enter the contract address from the command line in the search bar to see the details.