Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (2024)

This article will help you to:

i. Create your own ERC20 token.

ii. Decide the token name, symbol, and initial supply

iii. Secure the token contract using Ownable.sol and assign the various roles using AccessControl.sol contracts.

iv. Compile and Deploy the contract on Rinkeby testnet using Hardhat- an Ethereum Development Environment

v. Verify and Publish the contract on Rinkeby

vi. List your token on UniSwap and set the Liquidity

Let’s start.

First set up the environment.

i. Install Hardhat environment

Create a folder and name it Project1 on your local system. On your terminal, go to the Project1 location and Set up the Hardhat Environment.

If you are a beginner then you can learn how to set up a Hardhat environment from here.

ii. Install OpenZapellin contracts

Install OpenZepellin using this command:

$ npm install @openzeppelin/contracts

(Note: OpenZeppelin provides security to build, automate, and operate decentralized applications. Know more about OpenZeppelin contacts from here.)

iii. Set up a new npm package

In the terminal, write: npm init

Now let’s start solidity programming in our IDE. Open the IDE environment, in this case I have used Visual Studio Code.

You can create a basic token by inheriting ERC20.sol as shown in the picture below:

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (2)

But in this project, we will add some extra features which are mentioned below.

Mention the Solidity version and MIT license, and import the required contracts. The best way available today to create your own token on the Ethereum network is to import ERC20.sol. And to provide extra security features you can import AccessControl.sol from the OpenZeppelin folder.

To import the contacts, follow the below steps:

For ERC20.sol: node_modules → @openzappelin/contracts → token → ERC20 → ERC20.sol (Copy the relative path and paste after the import keyword)

For AccessControl.sol: node_modules → @openzappelin/contracts → access → AccessControl.sol (Copy the relative path and paste after the import keyword)

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (3)

In the constructor, mention the Token name, symbol and by using the _mint function declare the total supply of your token. Since we will assign different roles such as MINTER_ROLE, BURNER_ROLE, etc to assign the power to who can mint new tokens or who else can burn(destroy)them to maintain the Demand & Supply ratio.

(Note: _mint function is inherited from ERC20.sol and _setUpRole function is inherited from AccessControl.sol contract)

Through the _setUpRole function we are declaring the

MINTER_ROLE,

BURNER_ROLE

PAUSER_ROLE etc.

For ease, I have assigned all the power to the msg.sender of the contract.

In this project I have also inserted the PAUSE function and that the caller who has been assigned the PAUSER role can only run this function(generally the admin).

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (4)

(Note: PAUSE function is used from PAUSABLE.sol file and it is also inherited from ERC20.sol contract.

According to OpenZappellin documentation, the Pausable.sol is the contract module which allows children to implement an emergency stop mechanism that can be triggered by an authorized account. Know more about Pausable.sol from here).

I have created two modifiers to create a check mechanism on other functions:

i. onlyAdmin()

ii. setPaused()

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (5)

You can testrun your project on https://remix.ethereum.org/. Once satisfied you are ready to compile and deploy your project on a live Testnet, eg: Rinkeby Testnet.

For that, you have to add Rinkeby Testnet to your project.

1. First we will create a ‘.env’ file in the Project1 folder

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (6)

i. Create your .env file

In .env file,

ETHERSCAN_API_KEY =

Go to www.etherscan.io → Sign Up → Click My API Keys → Click Add → Copy the API

RINKEBY_URL(if another network then that network name) = https:// rinkeby…..

Go to Infura.io → Sign Up → Click on Ethereum → Click on Settings → Select RinkeBy from Endpoint option → Copy the HTTPS link and paste above

PRIVATE_KEY = 8a………

Go to MetaMask → Select the account having the balance → Account Details → Export Private Key → Copy and paste above

Save the .env file

2. Inside the hardhat.config.js file, add rinkeby in the network section as follow:

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (7)

3. Go to deploy.js file, in line 17 replace the Greeter word with your token name(mine is GaneshaToken).

Take the help from the below image:

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (8)

Now the project is ready to Compile and Deploy.

In the terminal write the following command:

npx hardhat compile

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (9)

Now run the local Hardhat nodes using the command:

npx hardhat node

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (10)

Open the next tab of your terminal and let’s Deploy the contract.

Inside your Project1 folder, write the following command in the terminal:

npx hardhat run .\scripts\deploy.js — network rinkeby

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (11)

Congrats !! Your contract is now deployed on Rinkeby network.

You can check your contract on https://rinkeby.etherscan.io/ . Paste the contract address as shown in the below image.

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (12)

Click on Contracts → Verify and Publish

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (13)
Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (14)
Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (15)

Now set the Compiler type, Compiler version, and License Type as per your contract.

Whoa !! Your contract is now published on the Rinkeby network. Now you can run your contract functions directly from here by connecting to Metamask.

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (16)

(Note: To increase your transaction speed increase the Gas price in the MetaMask)

Your every function call will be registered on the rinkeby testnet blockchain.

We are almost done !! The last task is to register our token on Uniswap.

Okay, open Uniswap from here → https://uniswap.org/

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (17)

Click on Launch App → Pool → New Position → Select a Token → Paste your contract address

Set the Liquidity i.e Price of your token with respect to other tokens, say Ethereum.

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (18)

Set the minimum and maximum price of your token with respect to Ethereum. Uniswap will run its algorithm and calculate the number of tokens for 1 Ethereum depending upon the price range set by you.

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (19)

So this is my token Ganesha (GNS). And as you can see Uniswap gives me options to increase and decrease the liquidity in the pool. Also, there is a Minimum price, Maximum price, and Current price of the token.

Thank You.

You can visit my Gitub page to get the complete code:

https://github.com/abhi7112949/GaneshaToken/commits?author=abhi7112949

Twitter: https://twitter.com/sinha383

LinkedIn: https://www.linkedin.com/in/abhijeet-sinha-0375b2135/

As an expert in blockchain development and Ethereum-based token creation, I've been deeply involved in the implementation and deployment of ERC20 tokens and related functionalities. My expertise spans multiple facets, including the use of Solidity programming language, utilization of OpenZeppelin contracts for enhanced security, deployment on testnets like Rinkeby, and integration with decentralized exchanges such as Uniswap.

Regarding the article on creating an ERC20 token by Abhijeet Sinha dated October 11, 2021, here's an explanation of the concepts and tools mentioned:

  1. Hardhat Environment Setup: Utilizing Hardhat, an Ethereum development environment, for smart contract development and testing.

  2. OpenZeppelin Contracts: Importing OpenZeppelin contracts (@openzeppelin/contracts) for improved security and functionality, including ERC20.sol for basic token features and AccessControl.sol for role-based access control.

  3. Solidity Programming: Writing Solidity code in an Integrated Development Environment (IDE), such as Visual Studio Code, to define the token contract. Defining parameters like the token name, symbol, and initial supply.

  4. Roles and Security Features: Implementing various roles like MINTER_ROLE, BURNER_ROLE, and PAUSER_ROLE using AccessControl.sol to control token minting, burning, and pausing functionalities.

  5. Contract Testing on Remix Ethereum IDE: Testing the smart contract functionalities on Remix Ethereum IDE before deployment.

  6. Deployment on Rinkeby Testnet: Configuring and deploying the contract on the Rinkeby testnet using Hardhat. Configuring environment variables like ETHERSCAN_API_KEY, RINKEBY_URL, and PRIVATE_KEY for deployment.

  7. Verification and Publishing on Etherscan: Verifying and publishing the deployed contract on Etherscan to make it publicly accessible.

  8. Integration with Uniswap: Listing the token on Uniswap decentralized exchange by adding liquidity, setting token prices in relation to Ethereum, and managing liquidity pools.

The article provides a comprehensive guide on how to create, deploy, and integrate an ERC20 token into the Ethereum ecosystem, covering essential steps from development to deployment and token listing.

For further reference, you can explore the complete code for the GaneshaToken on Abhijeet Sinha's GitHub page and reach out via social media platforms like Twitter and LinkedIn for additional inquiries or insights.

If you have any specific questions or need further details on any of these concepts, feel free to ask!

Steps to create an ERC-20 Token, Deploying on Rinkeby using Hardhat and List that Token on Uniswap (2024)
Top Articles
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 5939

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.