Deploy an ERC-20 Token on Humanity Testnet using Hardhat
This guide walks you through deploying an ERC-20 token smart contract on the Humanity Protocol network using Hardhat and MetaMask.
Prerequisites
Before you begin, you need to install the following dependencies:
Node.js v22.14.0 or later
⚠️ Note
If you are on Windows, we strongly recommend using WSL 2 when following this guide.
You can find the code for this tutorial in the following repo. Remember to rename your .env.example to .env adding your private key and Alchemy API Key
It covers the complete development workflow, from initial setup and configuration to deployment and verification. You'll learn how to set up Hardhat for the Humanity Protocol testnet, configure your environment variables, write and test an ERC-20 smart contract with optional initial token transfer functionality, deploy it to the network, and verify your deployed contract on the Humanity Protocol block explorer.
Before deploying your first smart contract to the Humanity Protocol testnet, you'll need to configure your wallet and get some testnet tokens.
If you haven't already, install the MetaMask browser extension and create a wallet.
⚠️
Always use a dedicated test wallet for development — never use a wallet that holds real assets. Testnets are for experimentation, and it's safer to separate your development activities from your personal or mainnet funds.
To connect MetaMask to the Humanity testnet and get some testnet tokens, follow the steps here:
📚 Working with Humanity Testnet
Project Setup
Now we have completed our wallet setup, let's first create the folder and basic structure of our project:
Add the following content to your package.json:
Install all the packages with:
Let's now create the folder structure for our project by creating contracts, scripts and test folders inside the /humanity-erc20-contract root folder. Also let's create an .env file and a hardhat.config.js file at the root level. Your folder structure should look like this:
Environment Configuration
Now inside our .env file add the following variables:
For this tutorial we are using MetaMask and the private key associated with our test account holding our testnet tokens. In order to get the private key from your account follow these instructions:
Replace <YOUR_PRIVATE_KEY> with the one you just copied from MetaMask.
In order to use the Alchemy API Key to connect with Humanity testnet network please follow this tutorial:
Once we have our Alchemy API Key, let's add it to our .env file replacing <YOUR_ALCHEMY_API_KEY> with your own Key.
⚠️ Alchemy API Key
If you do not have an Alchemy account you can still use
https://humanity-testnet.g.alchemy.com/publicas yourHUMANITY_TESTNETvariable but you may encounter errors during deployment later on due to polling to public endpoint for block confirmations too often.
Hardhat Configuration
Let's now configure Hardhat. Add the following to the hardhat.config.js:
Smart Contract
Inside our contracts folder let's create our smart contract. Let's call it DemoToken.sol:
This contract includes:
ERC-20 standard implementation using OpenZeppelin
Initial supply of 1,000,000 DEMO tokens minted to deployer
Optional initial transfer - Can send tokens to another address during deployment (gas efficient!)
Minting capability - Owner can mint additional tokens as needed
Ownership control - Owner can transfer ownership or renounce it
Use Cases
This token setup is ideal for:
Backend-controlled airdrops - Send tokens directly from distribution wallet
Treasury management - Send initial supply to multisig
Team allocations - Transfer to vesting contracts
Staking rewards - Fund reward pools
The optional initial transfer feature saves approximately ~21,000 gas compared to separate deployment and transfer transactions!
Testing
Inside our test folder let's create a test file to test our contract before deployment, so we are sure it works before sending it to the blockchain and spending any tokens. Let's call it DemoToken.test.js:
Deployment Script
Finally let's create a deployment script inside our scripts folder called deploy.js:
Compile the Contract
We are ready to compile our contract by running:
You should see output indicating successful compilation.
Run Tests
Let's first test our contract by running:
We should see something like this on our terminal:
Deploy to Humanity Protocol Testnet
Now we are finally ready to deploy our contract! You have two options:
Option A: Deploy with all tokens to deployer (default)
Option B: Deploy with initial token transfer (Recommended)
This saves gas by combining deployment and token transfer in a single transaction.
First, add to your .env file:
Then deploy:
You should see something like this in your terminal:
⚠️
If you encounter some errors, it's probably due to using the Alchemy public RPC endpoint. To avoid this, please get your own API key here. In any case, even with errors, your contract should be deployed!
View Your Contract on Explorer
In order to see your deployed contract, visit Humanity Protocol Testnet Explorer and search for your contract address using the TOKEN_CONTRACT_ADDRESS from the previous step and click on the item that pops up.
It will take you to your contract page. If you click on the Transactions tab you will see the details from your deployment transaction.

Manual Verification (if needed)
If automatic verification failed, you can verify manually using Hardhat:
Without initial transfer:
With initial transfer:
Example:
You should see something similar in your terminal:
You should see our contract has been verified and able to see our Solidity code, compiler and ABI details rather than just our Bytecode.

Interact with Your Contract
Besides viewing the contract, verifying gives us the ability to test our functions directly from the explorer. If we click on the Contract tab and then Write Contract sub-tab, we will see our DemoToken.sol functions and we can start calling them directly from the explorer.
⚠️
In order to interact with our contract we must connect to the Humanity Protocol website explorer by clicking on the Connect button located at the top right portion of the screen.
The explorer will give us also the option to simulate our transactions and will print the estimated gas for the real transaction.

Congratulations, you have successfully set up your development environment with Hardhat, connected your MetaMask wallet to the Humanity Protocol Testnet, obtained test tokens from the faucet, configured your project settings, and tested as well as deployed an ERC-20 token contract on the network.
Last updated