Deploy an ERC-20 Using Hardhat¶
IntermediateIntroduction¶
ERC-20 tokens are fungible tokens commonly used for creating cryptocurrencies, governance tokens, and staking mechanisms. Polkadot Hub enables easy deployment of ERC-20 tokens via Ethereum-compatible smart contracts and tools.
This guide demonstrates how to deploy an ERC-20 contract on Polkadot Hub TestNet using Hardhat, an Ethereum development environment. The ERC-20 contract can be retrieved from OpenZeppelin's GitHub repository or generated with the OpenZeppelin Contracts Wizard for Polkadot.
Prerequisites¶
Before you begin, ensure you have the following:
- A basic understanding of Solidity programming and ERC-20 fungible tokens.
- Node.js v22.13.1 or later installed.
- Test tokens for gas fees, available from the Polkadot faucet. See Get Test Tokens for a guide to using the faucet.
- A wallet with a private key for signing transactions.
Set Up Your Project¶
This tutorial uses a Hardhat ERC-20 template that contains all the necessary files.
To get started, take the following steps:
-
Clone the GitHub repository locally:
-
Install the dependencies using the following command:
This command will fetch all the necessary packages to help you use Hardhat to deploy an ERC-20 to Polkadot.
Configure Hardhat¶
If you started with the cloned Hardhat ERC-20 template, hardhat.config.ts is already configured to deploy to the Polkadot TestNet as shown in the example below:
import { HardhatUserConfig, vars } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
const config: HardhatUserConfig = {
solidity: {
version: "0.8.28",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
networks: {
polkadotTestnet: {
url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"),
accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [],
},
},
mocha: {
timeout: 40000,
},
};
export default config;
Tip
Visit the Hardhat Configuration variables documentation to learn how to use Hardhat to handle your private keys securely.
Compile the Contract¶
Next, compile the contract included with the template by running the following command:
If everything compiles successfully, you will see output similar to the following:
npx hardhat compile Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 Successfully generated 62 typings! Compiled 21 Solidity files successfully (evm target: paris).
Test the Contract¶
You can view the predefined test file at test/MyToken.test.ts. This example test includes verification of the following:
- The token name and symbol exist (confirms deployment) and are correct.
- The token owner is correctly configured.
- The initial token supply is zero.
- The owner can mint tokens.
- The total supply increases after a mint.
- Successful mints to different test addresses with expected account balance and total supply changes.
Run the tests using the following command:
If tests are successful, you will see outputs similar to the following:
npx hardhat test --network polkadotTestnet MyToken Deployment ✔ Should have correct name and symbol ✔ Should set the right owner ✔ Should have zero initial supply Minting ✔ Should allow owner to mint tokens ✔ Should increase total supply on mint Multiple mints ✔ Should correctly track balance after multiple mints 6 passing (369ms)
Deploy the Contract¶
You are now ready to deploy the contract to your chosen network. This example demonstrates deployment to the Polkadot TestNet. Deploy the contract as follows:
-
Run the following command in your terminal:
-
Confirm the target deployment network name and chain ID when prompted:
npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet ✔ Confirm deploy to network polkadotTestnet (420420417)? … yes Hardhat Ignition 🚀 Deploying [ TokenModule ] Batch #1 Executed TokenModule#MyToken Batch #2 Executed TokenModule#MyToken.mint [ TokenModule ] successfully deployed 🚀 Deployed Addresses TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3
Congratulations! You've successfully deployed an ERC-20 token contract to Polkadot Hub TestNet using Hardhat. Consider the following resources to build upon your progress.
Where to Go Next¶
-
Guide Deploy an NFT
Walk through deploying an NFT to the Polkadot Hub using Hardhat.
-
Guide Create a DApp
Learn step-by-step how to build a fully functional dApp that interacts with a smart contract deployed via Hardhat.
| Created: January 14, 2026