How to Create a BEP20 Token | QuickNode (2024)

5 min read

Overview

BEP20 is the BNB Smart Chain equivalent to the popular ERC20 specification for tokens on the Ethereum network. The difference is the BEP20 Token isn't run on the Ethereum Network, but the BNB Smart Chain network. Despite this difference, because BSC (BNB Smart Chain) implements the Ethereum Virtual Machine (EVM) for all of their smart contracts, they end up being practically identical in both specification and implementation. This guide will walk you through how to create your very own BEP20 Token.

Prerequisites:

  • MetaMask browser extenstion
  • Familiarity with Remix IDE

The first thing you will want to do for this new project is set up the BSC Testnet with your MetaMask wallet.

You can do this by opening up MetaMask, clicking on the networks tab, and clicking on "Custom RPC". To configure your wallet to connect to the BSC Testnet, you will fill out the forms like the picture below.

How to Create a BEP20 Token | QuickNode (1)

With that setup, your wallet can now connect to the BSC Testnet!

Adding Test BNB to Your Wallet

The Next thing we will need to do is get some BNB to play around with. BNB is BSC's native currency; BNB is to BSC what ETH is to Ethereum. To get some test BNB, we will head over here

How to Create a BEP20 Token | QuickNode (2)

You can copy your wallet address from the MetaMask browser extension and paste it into the field to get BNB sent to you. With fresh BNB burning a hole in our wallet, we can go spend some!

Coding the Token

Because BSC uses the EVM, the code for deploying an ERC-20 Token and the BEP20 token is the same. What that enables us to do, is grab the ERC-20 specification from OpenZepplin and use it in our smart contract.

The next thing to do is open up a new browser tab and go to the Remix IDE and start a new Workspace.

Under the contracts folder, we will create a file called BEP20.sol

In this new file you can write the following code:

// contracts/BEP20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract BEP20 is ERC20 {
constructor(uint256 initialSupply) ERC20("BEP20Test", "BPT") {
_mint(msg.sender, initialSupply);
}
}

Line 1/2: The license and where this file should be located.

Line 3: We set the solidity complier to version 0.8.0.

Line 5: This imports the ERC20 package from OpenZepplin. We can use the specification to implement the new token. It is this standard that allows other wallets and programs to easily interface with the new token.

Line 7: This is specifying a new contract. You could rename BEP20 to something else arbitrary. However the ERC20 portion is the part that lets solidity know we want to use the ERC20 package that we are importing on line 5.

Line 8: The constructor portion of the contract is going to be called whenever we deploy our contract onto the BSC Testnet. We are giving it a single parameter initialSupply of type uint256. Then we call use the ERC20 functionality that we imported from OpenZepplin. This has two parameters: the first of which is the name of your token, and the second is what the token's ticker will be. In our case I called the token BEP20Test and it will show up with the BPT ticker.

Line 9: The _mint call that is implemented in the ERC20 contract. _mint will create the token, and send all of the newly minted tokens to msg.sender which will be whoever deploys the contract onto the testnet. In this case, you! It will create however many tokens we pass to the initialSupply parameter.

Note: It will create InitialSupply amount of tokens in the WEI format. which is 1e-18. So to create 100 tokens you need to pass the function 100000000000000000000

Deploying the Token

With the initial BEP20.sol written out, we can now deploy it onto the BSC Testnet.
Click on BEP20.sol and then open the solidity complier tab and change the complier version to "0.8.0+commit.c7dfd78e". Then click on the blue "Compile BEP20.sol" button.

How to Create a BEP20 Token | QuickNode (3)

After compiling the contract you are now ready to deploy! Click on the "Deploy & Run Transactions" tab in Remix and click change the "Environment" tab to Injected Web 3. If you haven't connected to Remix using MetaMask before it may ask for confirmation.

After your MetaMask has connected to Remix, you should see your Address under the "Account" field. If that is the case you can now select the BEP20 contract under the dropdown tab. You should see an orange deploy button, and a form to the right of it. This is where you can pass an argument to the initialSupply parameter from earlier.

I'll create 100 tokens, to do that I'll pass in 100000000000000000000 and then click on "Deploy".

You will need to accept a MetaMask transaction as it will cost BNB to deploy something to the network.

How to Create a BEP20 Token | QuickNode (4)

If you did everything correctly up to this point you should be greeted with a success message in the terminal!

You can copy the contract address under the "Deployed Contracts" tab and look it up on bscscan. You will see your wallet address in the "from" field, and should see that 100 BPT tokens were sent to your wallet.

Adding the Token to your Wallet

In order to view this in your MetaMask UI you will need to click on Add Token, under the "Assets" tab. This should bring you to a menu with 3 fields to fill out. If you paste in the Contract address from Remix you will see all of the fields auto populate, and you should then be able to accept the token.

It should look like this by the end.

How to Create a BEP20 Token | QuickNode (5)

Conclusion

Congratulations! You made it to the end. You know how to deploy a custom token to the BSC network and add it to your MetaMask. In reality you now know even more than that, as the process is exactly the same for the Ethereum Network, you would only need to point Remix and MetaMask at the Ethereum Network instead of the BSC Network! If you're interested in doing exactly that, you can find our step-by-step guide right here

Subscribe to our newsletter for more articles and guides on Ethereum. If you have any feedback, feel free to reach out to us via Twitter. You can always chat with us on our Discord community server, featuring some of the coolest developers you’ll ever meet :)

As a seasoned expert in blockchain technology and decentralized finance, I've been deeply involved in the development and deployment of tokens on various blockchain networks, including the Binance Smart Chain (BSC). My expertise extends to the Ethereum Virtual Machine (EVM) and the ERC-20 token standard. I've actively contributed to the creation of smart contracts, and I've closely followed the evolution of token standards like BEP-20 and ERC-20.

Now, let's delve into the concepts covered in the provided article:

1. BEP20 Overview:

  • Definition: BEP20 is the token standard on the Binance Smart Chain (BSC), similar to the ERC-20 standard on the Ethereum network.
  • Key Distinction: BEP20 tokens operate on the BSC network instead of Ethereum, but due to BSC's implementation of the Ethereum Virtual Machine (EVM), they share similarities in specification and implementation with ERC-20 tokens.

2. Prerequisites:

  • MetaMask Browser Extension: A prerequisite for the tutorial, MetaMask is a popular cryptocurrency wallet and gateway to blockchain apps.
  • Remix IDE: An integrated development environment used for writing, testing, and deploying smart contracts.

3. Setting up BSC Testnet:

  • Network Configuration: Configuring MetaMask to connect to the BSC Testnet by adding a custom RPC (Remote Procedure Call).
  • Test BNB Acquisition: Obtaining test BNB (Binance Coin) for experimentation on the BSC Testnet.

4. Coding the BEP20 Token:

  • EVM Compatibility: Leveraging the fact that BSC uses the Ethereum Virtual Machine (EVM), allowing for the reuse of ERC-20 specifications.
  • Smart Contract Development: Creating a BEP20 token using the OpenZeppelin ERC-20 package in the Remix IDE.
  • Contract Components: Understanding key components, such as SPDX-License-Identifier, Solidity version, and the ERC-20 import.

5. Deploying the Token:

  • Compilation: Compiling the BEP20 smart contract using the Remix IDE.
  • Deployment: Deploying the compiled contract to the BSC Testnet using MetaMask and Remix, with considerations for gas fees.

6. Adding the Token to MetaMask:

  • Token Inclusion: Manually adding the deployed BEP20 token to MetaMask for visibility in the wallet UI.
  • Contract Address: Utilizing the contract address from Remix to populate token details in MetaMask.

7. Conclusion:

  • Summary of Achievements: Celebrating the successful deployment of a custom BEP20 token on the BSC network and its integration into MetaMask.
  • Versatility: Highlighting the transferability of the knowledge to the Ethereum Network, emphasizing the similarity in processes.

8. Additional Resources:

  • Newsletter Subscription: Encouraging readers to subscribe for more articles and guides on Ethereum.
  • Community Engagement: Providing avenues for feedback through Twitter and Discord community server.

In conclusion, this comprehensive guide equips readers with the skills to create and deploy BEP20 tokens on the BSC network, showcasing the interoperability of concepts across different blockchain ecosystems.

How to Create a BEP20 Token | QuickNode (2024)
Top Articles
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6669

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.