Skip to main content

Deploy a ERC20 token contract

If you don’t have an existing ERC20 token to deploy, you can use one from the Postchain EIF Contracts repository. In this example, we will deploy the ALICE token using its contract.

Prerequisites

Before proceeding, ensure you have the following:

  • ERC20 token contract: Use the ALICE token or any other ERC20 contract.
  • Node.js and Yarn: Ensure both are installed on your system.
  • MetaMask: Install and configure MetaMask, and connect it to the BSC Testnet.
  • BNB for gas fees: Obtain some BNB for gas fees from the BSC Testnet Faucet.

Step 1: Clone the postchain-eif-contracts repository

First, clone the repository containing the token contracts:

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

Step 2: Install dependencies

Install all required project dependencies by running the following command:

yarn install
tip

If you encounter any issues, try removing the yarn.lock file and regenerating it with the following commands:

rm yarn.lock
yarn install

Step 3: Set up environment variables

You’ll need to create a .env file to store sensitive information, such as your mnemonic and API keys.

Create the .env file by copying the example:

cp .env.example .env

Edit the .env file with your details:

MNEMONIC="your mnemonic phrase"
BSC_TESTNET_RPC_URL="https://data-seed-prebsc-1-s1.binance.org:8545/"
  • MNEMONIC: This is the mnemonic from your MetaMask wallet or another wallet you control.
  • BSC_TESTNET_RPC_URL: URL for the Binance Smart Chain (BSC) Testnet.

Step 4: Compile the contract

Before deploying, ensure the contract is compiled:

yarn compile

This will generate the compiled contract artifacts.

Step 5: Deploy the ALICE token to BSC Testnet

To deploy the ALICE ERC20 token contract, use the provided deployment script from the repository:

yarn deploy:alice --network bsc_testnet
  • deploy:alice: This script handles the deployment of the ALICE token contract.
  • --network bsc_testnet: Specifies that the contract should be deployed to the Binance Smart Chain (BSC) Testnet.

Upon a successful deployment, the terminal will display the contract's address. For example:

token deployed to:  0x22Ea9bF66Ee38E39A333773e584f37216136700A
tip

Be sure to copy and save the deployed contract address for later use.