Skip to main content

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:

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:

  1. Open MetaMask.
  2. On the welcome screen, choose “Import an existing wallet”.
  3. Select “Import account using private key”.
  4. Paste the private key from the previous step.

If you already have an account in MetaMask:

  1. Click on your account avatar (top-right corner).
  2. Select “Add account or hardware wallet”“Import account”.
  3. 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 the ALICE 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.