Deploy an ERC20 token
On this page
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
Terminal
git clone https://gitlab.com/chromaway/core/postchain-eif.git
cd postchain-eif/postchain-eif-contracts1. Install dependencies
Terminal
npm install2. Set up environment variables
Create a .env file:
Terminal
cp .env.example .envGenerate a valid mnemonic
Use the BIP39 mnemonic generator to create a 12-word phrase.
Paste it into .env:
INI
MNEMONIC="your twelve-word mnemonic here"
REPORT_GAS=trueConfigure API keys (Optional)
Update .env:
INI
# 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_KEYfrom BscScan.
3. Import your account into MetaMask
Derive the private key from your mnemonic
Terminal
node -e "const { Wallet } = require('ethers'); console.log(Wallet.fromPhrase(process.argv[1]).privateKey)" "$(grep MNEMONIC .env | cut -d '=' -f2 | tr -d '"')"or for powershell
Output
$mnemonic = (Get-Content .env | Select-String -Pattern "^MNEMONIC=" | ForEach-Object { $_.Line -replace '^MNEMONIC=', '' } | ForEach-Object { $_ -replace '"', '' }); node -e "const { Wallet } = require('ethers'); console.log(Wallet.fromPhrase(process.argv[1]).privateKey)" $mnemonicImport 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
Terminal
npx hardhat compile5. Deploy the ERC20 token
Run the following command:
Terminal
npx hardhat deploy:alice --network bsc_testnetdeploy:alice: Deploys theALICEERC20 token contract.--network bsc_testnet: Deploys to Binance Smart Chain Testnet.
After successful deployment, the contract address will be displayed:
Output
Token deployed to: 0x....................