How to Deploy an ERC-20 Token on the BNB Smart Chain (BNB Chain)

we will walk you through the steps to deploy an ERC-20 token on the BNB Smart Chain (BNB Chain) using Remix IDE. We will use a simple ERC-20 token contract, called AlgoToken, to demonstrate how to create a new token on the network.

Prerequisites

Before we begin, make sure you have the following:

  • A MetaMask wallet (or any other Ethereum-compatible wallet).

  • Some BNB for transaction fees (You can get testnet BNB from the Binance Smart Chain Testnet Faucet if you are using the testnet).

  • Remix IDE access: https://remix.ethereum.org/

Step 1: Open Remix IDE

Visit remix IDE in your browser. Remix is an open-source web and desktop application used to write, compile, deploy, and debug smart contracts written in Solidity.

Step 2: Write the ERC-20 Token Contract

In the Remix IDE, create a new solidity file by going to the "File Explorer" on the left sidebar and clicking the "+" button. Name your file AlgoToken.sol

Now, copy and paste the following Solidity code into your new file:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract AlgoToken {
    string public name = "Algo Token";
    string public symbol = "ALGO";
    uint8 public decimals = 18;
    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    constructor(uint256 _initialSupply) {
        totalSupply = _initialSupply * 10 ** uint256(decimals);
        balanceOf[msg.sender] = totalSupply; // Assign all initial tokens to the contract creator
    }

    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(_to != address(0), "Invalid address");
        require(balanceOf[msg.sender] >= _value, "Insufficient balance");

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(msg.sender, _to, _value);

        return true;
    }

    function approve(address _spender, uint256 _value) public returns (bool success) {
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_from != address(0), "Invalid address");
        require(_to != address(0), "Invalid address");
        require(balanceOf[_from] >= _value, "Insufficient balance");
        require(allowance[_from][msg.sender] >= _value, "Allowance exceeded");

        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        allowance[_from][msg.sender] -= _value;
        emit Transfer(_from, _to, _value);

        return true;
    }
}

This is a basic ERC-20 token contract with functions for transferring tokens, approving token allowances, and transferring tokens on behalf of others.

Step 3: Compile the Contract

Once you've pasted the code into Remix, you'll need to compile it. Follow these steps:

  1. Go to the "Solidity Compiler" tab in the left sidebar (the icon that looks like a compiler).

  2. Select the version 0.8.0 (or any version compatible with your contract).

  3. Click the "Compile AlgoToken.sol" button to compile the contract.

If the compilation is successful, you should see a green checkmark indicating no errors.

Step 4: Deploy the Contract

Now that the contract is compiled, it’s time to deploy it to the BNB Smart Chain network.

  1. Go to the "Deploy & Run Transactions" tab (the icon that looks like a "deploy" button).

  2. In the "Environment" dropdown, select "Injected Web3" to connect Remix to your MetaMask wallet.

    • If this is your first time connecting Remix to MetaMask, you’ll need to authorize Remix to access your wallet.
  3. Ensure that your MetaMask wallet is connected to the BNB Smart Chain. You can either connect to the BNB Mainnet or the BNB Testnet.

    • To connect to the testnet, make sure you're on the Binance Smart Chain Testnet in MetaMask.
  4. In the "Account" section, select the address that will deploy the contract.

  5. In the "Value" field, leave it empty since we're not sending any Ether with the deployment.

  6. In the "Gas Limit" field, set a reasonable gas limit (e.g., 3000000).

Next, you'll need to input an initial supply for your token. For example, if you want to create 1,000,000 tokens, enter 1000000 in the constructor's input field.

  1. Click the "Deploy" button, and MetaMask will ask you to confirm the transaction.

  2. Confirm the transaction in MetaMask and wait for the deployment to complete.

Step 5: Verify Deployment

Once the contract is successfully deployed, Remix will display the contract's address on the BNB Smart Chain. You can also verify the contract by interacting with it via MetaMask.

  1. In MetaMask, you should see your deployed token under the "Assets" tab (if it is not visible, add the token using the contract address).

  2. On BNB Explorer, you can view the contract and transaction details by entering the contract address.

Step 6: Interact with the Token

Now that your ERC-20 token is live, you can interact with it:

  1. Transfer Tokens: Use the transfer function to send tokens to other addresses.

Approve and TransferFrom: Use the approve and transferFrom functions to manage allowances and transfer tokens on behalf of others.

Verify your contract on BNB Testnet

To verify your contract on BNB Testnet using BSCScan, follow the steps below with the details you provided:

Step 1: Go to Contract Verification Page

Open this URL to start verifying your contract: BSCScan Verify Contract.

Step 2: Enter the Required Information

Here’s what you need to fill out:

  1. Contract Address:

    • You have already provided the contract address: 0xe4f379fFA53cF699cBbA949A9A03118e6fA796Fb. This should be pre-filled in the field.
  2. Compiler Type:

    • Choose Solidity (Single file) because you are using a single Solidity file.
  3. Compiler Version:

    • Select 0.8.0+commit.c7dfd78e or a compatible version (e.g., 0.8.7). You are using ^0.8.0 in your contract, so make sure the selected version matches your deployed contract's version.

      • In this case, you can safely use 0.8.0+commit.c7dfd78e.
  4. Open Source License Type:

    • Choose MIT License (as this is a commonly used license for smart contracts).
  5. I Agree to the Terms of Service:

    • Check the box that says, "I agree to the terms of service."

Step 3: Constructor Arguments (If Applicable)

In the transaction input data, you have provided an initial supply of 1000. If needed, BSCScan will automatically detect and decode the constructor arguments (which in your case is 1000 tokens). You do not need to manually enter anything here unless the platform explicitly asks for it.

Step 4: Submit Verification

  • After filling out the required information, click on the Verify and Publish button.

Step 5: Wait for Confirmation

Once you submit the verification request, BSCScan will process it. If everything is correct, the contract will be verified, and you will see the source code displayed on the BSCScan page for your contract.

0
Subscribe to my newsletter

Read articles from Walli Prasad Roy directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Walli Prasad Roy
Walli Prasad Roy