# Deploy an ERC20 token · Chromia Docs (concept)

> This section walks through deploying the ALICE ERC20 token on the BSC Testnet using Hardhat.

Source: https://docs.chromia.com/ecosystem/bridge/deploy-bridge/deploy-erc20-token/

# Deploy an ERC20 token

On this page

* [Prerequisites](#prerequisites)
* [1. Install dependencies](#1-install-dependencies)
* [2. Set up environment variables](#2-set-up-environment-variables)
* [Generate a valid mnemonic](#generate-a-valid-mnemonic)
* [Configure API keys (Optional)](#configure-api-keys-optional)
* [3. Import your account into MetaMask](#3-import-your-account-into-metamask)
* [Derive the private key from your mnemonic](#derive-the-private-key-from-your-mnemonic)
* [Import into MetaMask](#import-into-metamask)
* [4. Compile the contract](#4-compile-the-contract)
* [5. Deploy the ERC20 token](#5-deploy-the-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](https://docs.chromia.com/get-started/installation/)**
* **[Node.js](https://nodejs.org/)**
* **[Hardhat](https://www.npmjs.com/package/hardhat)**
* **[MetaMask](https://metamask.io/)** or a compatible wallet.
* **[Test BNB tokens](https://www.bnbchain.org/en/testnet-faucet)** or the respective native tokens for gas fees.
* **[Postchain EIF contracts repository](https://gitlab.com/chromaway/core/postchain-eif.git)**

Terminal

```
git clone https://gitlab.com/chromaway/core/postchain-eif.git
cd postchain-eif/postchain-eif-contracts
```

## 1. Install dependencies

Terminal

```
npm install
```

## 2. Set up environment variables

Create a `.env` file:

Terminal

```
cp .env.example .env
```

### Generate a valid mnemonic

Use the [BIP39 mnemonic generator](https://iancoleman.io/bip39/) to create a 12-word phrase.

Paste it into `.env`:

INI

```
MNEMONIC="your twelve-word mnemonic here"
REPORT_GAS=true
```

### Configure 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_KEY` from [BscScan](https://bscscan.com/myapikey).

## 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

Terminal

```
$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)" $mnemonic
```

### 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

Terminal

```
npx hardhat compile
```

## 5. Deploy the ERC20 token

Run the following command:

Terminal

```
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:

Terminal

```
Token deployed to: 0x....................
```

warning

Copy and save the actual deployed contract address for later use.

[View this page on docs.chromia.com](https://docs.chromia.com/ecosystem/bridge/deploy-bridge/deploy-erc20-token/)Content mirrored from the live docs
