How to create a BEP-20 token on Binance Smart Chain

How to create a BEP-20 token on Binance Smart Chain

BEP-20 is a Binance Smart Chain token standard that lets you transfer your tokens between different blockchain networks. It was designed to offer a flexible structure for developers to create a variety of tokens. In this article, we’ll discuss the key concepts of Binance Smart Chain and token development on it.

What is Binance Smart Chain?

The Binance Smart Chain(BSC) is a blockchain system developed by the crypto-trading platform Binance. Since its launch in 2020, it has established itself as one of the leading blockchains for DeFi and dApp development. Some of its key features include smart contract functionality and compatibility with Ethereum Virtual Machine (EVM).

Binance Smart Chain is completely independent of the Binance network. This means that even if the Binance network is down, Binance Smart Chain can still run normally. It is built on a dual-chain architecture. It allows users to develop their decentralized apps and digital assets on a single blockchain.

BSC is governed by a Proof-of-Stake (PoS) consensus algorithm that enables users to stake BNB tokens so that they can become validators. They can also transfer their assets from one blockchain network to another in a quick and hassle-free manner. This interoperable nature allows for myriad applications in the decentralized finance area.

Related Article: How to launch a DeFi project.

Advantages of using Binance Smart Chain

Binance Smart Chain has several advantages over other blockchains when it comes to digital asset development. Some of the top benefits can be seen as follows:

  • An affordable transaction fee that goes as low as one cent.
  • Allows for the development of smart contracts.
  • Extensive ecosystem for validators, token holders, developers, and other users.
  • Enhanced performance with potential for upgrade.
  • Equipped with a network that can produce a block in three seconds.
  • It supports cross-chain DeFi mechanisms that can improve interoperability.
  • The growing audience of millions of users across Binance and Binance DEX.
  • Robust staking mechanism for BNB.

The BEP-20 Token Standard

The introduction of BEP-20 has engendered a healthy amount of competition with ERC-20. The Binance Smart Chain enables users to develop tokens in a simple and user-friendly manner. Each token conforms to a standard known as BEP-20. This standard is essentially an extension of the Ethereum token standard ERC-20. It defines how a token based on BEP-20 can be spent and used. It also has information on who can spend these tokens. BEP-20 gives developers a flexible token standard to develop a wide range of tokens. For instance, developers can use BEP-20 tokens to represent an array of digital assets such as stablecoins, governance tokens, business shares, etc. 

A token standard like BEP-20 can guarantee basic functionalities for the token, like transferring, returning a balance, viewing token ownership, etc. Users can swap BSC tokens with the normal Binance Chain tokens that conform to their standard, BEP-2. All transactions that take place with these tokens on the Binance chain will require a fee paid in BNB. This fee works as compensation for validators who secure the network. Additionally, these tokens can be used to create a native asset or a pegged token. These tokens are also available for assets like Bitcoin, Ethereum, USDT, LINK, BAND, ADA, DAI, LTC, EOS, and more.

Difference between BEP-20 and BEP-2

BEP-20 refers to a token standard on the Binance Smart Chain and acts as an extension of the ERC-20 token standard. Surprisingly, BEP-20 is not the only token standard developed by Binance albeit the most popular. BEP-20 tokens are similar to the BEP-2 tokens in various aspects. Both BEP-2 tokens and BEP-20 tokens function through the use of Binance Coin (BNB). This stems from the fact that BEP-2 and BEP-20 are designed with dual chain architecture, where the Binance Chain and Binance Smart Chain support each other. The tokens also work similarly and their transfer is subject to a fee in terms of BNB which acts as the incentive model of the consensus algorithm. Therefore, any transfer of the BEP20 token will have a transfer fee in BNB which will be given to the validators. 

The main difference between the BEP-2 and BEP-20 is that they work on different blockchains. The BEP-2 token standard is meant for the Binance Chain, while this token standard works with the Binance Smart Chain. The BEP-20 token is compatible with both ERC-20 and BEP-2 (Binance Chain Token) since they are similar.

During the creation of a Multicoin account, the BEP-2 address would be the BNB address on your trust wallet, while the BEP-20 address would be the coin called “SmartChain”. The BEP-2 address starts with “bnb”. On the other hand, BEP-20 addresses start with 0x just like an Ethereum address.

Advantages of BEP-20

Here are the advantages and benefits that make it a more worthy asset for businesses.

  • BEP-20 is compatible with both Binance and Ethereum platforms. 
  • Completely backed by BNB.
  • Offers a flexible platform that developers can use as a template for token development and launch.
  • Users get BNB as an additional fee when they use BEP-20.
  • Supports several other tokens on the BSC network.
  • These tokens can be exchanged with BEP-2 tokens via the Binance Chain Wallet extension.
  • The development of native tokens can be facilitated on this tokens.
  • Other tokens of the Binance Smart Chain can be easily pegged with BEP-20.
  • A wide array of assets can be represented through these tokens, such as cryptos, fiat currencies, etc. 
  • A smart contract can be embedded in the smart chain network.

How to create a BEP-20 token on Binance Smart Chain

To create a BEP-20 token, you must first create a smart contract. Most smart contracts are written in an object-oriented, high-level language called Solidity. This language is statically typed, supports inheritance, libraries, and complex user-defined types among other features. Solidity also has several libraries and tools that provide implementations of standards like ERC-20 and ERC-721. There are also a plethora of components that can be used to build custom contracts.

The major steps that you will need to follow for BEP-20 token creation are given as follows:

Step 1: Create a new file called TokenName.sol. After your file has been created on Solidity, you will need to write a code for your smart contract.  You can make use of the code given below as a guide to this step. After you have added the code, set the compiler version of Solidity to the token.sol file version.

Guide for smart contract code:

// Current Version of solidity pragma solidity ^0.8.4;

// Main coin information contract Token {

    // Initialize addresses mapping mapping
    (address => uint) public balances;'

    // Total supply (in this case 1000 tokens)
    uint public totalSupply = 1000 * 10 ** 18;

    // Tokens Name
    string public name = “My Token”;

    // Tokens Symbol
    string public symbol = “MTK”;

    // Total Decimals (max 18)
    uint public decimals = 18;

    // Transfers
    event Transfer(address indexed from, address indexed to, uint value);

    // Event executed only ones upon deploying the contract
    constructor() {
          // Give all created tokens to address that deployed the contract balances[msg.sender] = totalSupply;

    }

    // Check balances
    function balanceOf(address owner) public view returns(uint) { return balances[owner];
    }

    // Transfering coins function
    function transfer(address to, uint value) public returns(bool) {
         require(balanceOf(msg.sender) >= value, ‘Insufficient balance’);
         balances[to] += value;
         balances[msg.sender] -= value;
         emit Transfer(msg.sender, to, value);
         return true;
     }
}

Step 2: In the second step, you will need to acquire a wallet for the storage of your tokens. You can easily buy, store and send tokens through MetaMask, one of the most popular digital asset management platforms in the market today. This is a relatively easy step. All you have to do is install and set up MetaMask. You will be given prompts during the entire process. After installation, click on “Create a wallet”. Note down the backup seed phrase and keep it carefully. If you lose this password, you will not be able to access your wallet again.

Step 3: For this step, you will have to connect MetaMask to the Binance Smart Chain. To do this, you will first need to configure your wallet. Go to ‘Settings’, which you will find in the drop-down menu on the top-right of the MetaMask webpage. Once you are on the Settings page, locate the Networks menu. Click on ‘Add Network’ in the top-right corner to manually add the Binance Smart Chain. 

Two networks can be used here: the Testnet or the Mainnet. For this tutorial, we will use Testnet. You can fill in the parameters given below: 

Testnet

Network Name: Smart Chain – Testnet
New RPC URL: https://data-seed-prebsc-1-s1.binance.org:8545/
ChainID: 97
Symbol: BNB

Block Explorer URL: https://testnet.bscscan.com

After you save the network, you will see that the network has automatically been set to Testnet and the units will be denominated in BNB instead of ETH.

Step 4: Head on to Binance Smart Chain Faucet and paste your BSC address into the form.

Click on the Give me BNB dropdown and select the amount you wish to receive. Your funds will then appear in your Testnet wallet.

You are now ready to deploy your first contract and start making transactions.

Is Binance Smart Chain the future?

Given the spectacular growth of Binance Smart Chain development in recent months, it appears that more BEP20 tokens will be making their way into the crypto sphere. Binance Smart Chain efficiently fills the gap between various blockchain and dramatically extends the functionality of the original Binance Chain.