Deploy an ERC20 token
This section walks through deploying the ALICE
ERC20 token on the BSC testnet using Hardhat.
This is intended for users who don't have an existing ERC20 token and need one for testing.
Prerequisites
Before proceeding, ensure you have the following:
- Chromia CLI
- Node.js
- Hardhat
- MetaMask or a compatible wallet.
- Test BNB tokens or the respective native tokens for gas fees.
- Postchain EIF contracts repository
1. Install dependencies
npm install
2. Set up environment variables
Create a .env
file:
cp .env.example .env
Generate a valid mnemonic
Use the BIP39 mnemonic generator to create a 12-word phrase.
Paste it into .env
:
MNEMONIC="your twelve-word mnemonic here"
REPORT_GAS=true
Configure API keys
Update .env
:
# Set API keys for Ethereum, BSC scan, and BASE scan
ETHERSCAN_API_KEY=your_etherscan_api_key
BSCSCAN_API_KEY=your_bscscan_api_key
BASESCAN_API_KEY=your_basescan_api_key
- Get
BSCSCAN_API_KEY
from BscScan.
3. Import your account into MetaMask
Derive the private key from your mnemonic
node -e "const { Wallet } = require('ethers'); console.log(Wallet.fromPhrase(process.argv[1]).privateKey)" "$(grep MNEMONIC .env | cut -d '=' -f2 | tr -d '"')"
Import into MetaMask
If you're setting up MetaMask for the first time:
- Open MetaMask.
- On the welcome screen, choose “Import an existing wallet”.
- Select “Import account using private key”.
- Paste the private key from the previous step.
If you already have an account in MetaMask:
- Click on your account avatar (top-right corner).
- Select “Add account or hardware wallet” → “Import account”.
- Paste the private key from the previous step.
4. Compile the contract
npx hardhat compile
5. Deploy the ERC20 token
Run the following command:
npx hardhat deploy:alice --network bsc_testnet
deploy:alice
: Deploys theALICE
ERC20 token contract.--network bsc_testnet
: Deploys to Binance Smart Chain testnet.
After successful deployment, the contract address will be displayed:
Token deployed to: 0x....................
warning
Copy and save the actual deployed contract address for later use.