How to create and deploy a BEP-20 token to the Binance smart chain - LogRocket Blog (2024)

BEP-20 is the token standard of the Binance Smart Chain (BSC). The Binance Smart Chain is a programmable blockchain with support for smart contracts and EVM compatibility. This makes it a good candidate for building decentralized applications.

How to create and deploy a BEP-20 token to the Binance smart chain - LogRocket Blog (1)

To interact with the BSC blockchain, a token based on the BEP-20 standard, BNB, is required to pay for transactions, just like Ether is used to pay for gas fees in the Ethereum blockchain. In fact, the BEP-20 standard is an extension of the ERC20 standard on Ethereum. This makes it possible to build decentralized apps on the Binance Smart Chain using current Ethereum tooling.

In this tutorial, we’ll code a sample BEP-20 token by implementing the BEP-20 token standard, deploy it to the Binance Smart Chain testnet using Remix, verify the token source code on BscScan, and, finally, import the deployed token into MetaMask.

We’ll cover the following in detail:

  • Implementing the BEP-20 Token Proposal
  • Deploying the token contract using Remix
  • Verifying and publishing your token contract on BscScan
  • Importing the token into MetaMask

This guide assumes prior knowledge of Solidity and EVM. Here’s a good resource on Solidity and one on EVM.

Implementing the BEP-20 Token Proposal

A BEP-20 token requires certain functions to enable other accounts to interact with it properly. You can take a look at these as outlined in the official BEP-20 proposal. I recommend reading through the proposal to familiarize yourself with the required functions.

Most real-world tokens, however, extend this proposal in different ways. For example, most tokens add the ability to:

  • Mint and burn tokens
  • Transfer ownership of the token contract to a different address
  • Pause/play the token contract as an emergency stop mechanism

For the purposes of this tutorial, we’ll implement the base BEP-20 proposal and allow minting and burning of tokens. You can extend this even more as an exercise to get more familiar with working with tokens.

There are a few prerequisites to coding a BEP-20 token:

After coding the token in Remix, you can test, and then deploy it to a public network.

For now, open Remix and create a new Token.sol file under /contracts. Make sure it is open in the editor.

Let’s start coding out the BEP-20 token!

How to create and deploy a BEP-20 token to the Binance smart chain - LogRocket Blog (2)

Declare a license and the version of Solidity the token is written in (we’ll be using the latest version 0.8 and above.

// SPDX-License-Identifier: GPL-3.0pragma solidity >=0.8.0;

Create a new contract declaration called Token.

contract Token { // All subsequent code will be inside this block}

Next, let’s initialize the variables and events required to implement the BEP-20 token standard one by one:

contract Token { string public name; // Holds the name of the token string public symbol; // Holds the symbol of the token uint8 public decimals; // Holds the decimal places of the token uint256 public totalSupply; // Holds the total suppy of the token address payable public owner; // Holds the owner of the token /* This creates a mapping with all balances */ mapping (address => uint256) public balanceOf; /* This creates a mapping of accounts with allowances */ mapping (address => mapping (address => uint256)) public allowance; /* This event is always fired on a successfull call of the transfer, transferFrom, mint, and burn methods */ event Transfer(address indexed from, address indexed to, uint256 value); /* This event is always fired on a successfull call of the approve method */ event Approve(address indexed owner, address indexed spender, uint256 value);... code continues below (1)

If you read the proposal, you’ll notice the variables share the same name as some functions. This is useful because in Solidity v0.8 and above, public variables automatically generate getter functions.

So, in effect, we’ll have the following functions available automatically:

  • name()
  • symbol()
  • decimals()
  • totalSupply()
  • owner()
  • balanceOf()
  • allowance()

Next, we define the constructor of the token contract. In this constructor, we specify the token’s details, such as name, symbol, etc. We mint (i.e., create) a specified amount of tokens and transfer them to the owner of the token.

Currently, we hardcode these values directly inside the constructor definition, but it’s also possible to retrieve them from the constructor arguments.

... code continues from above (1) constructor() { name = "RandomToken"; // Sets the name of the token, i.e Ether symbol = "RDT"; // Sets the symbol of the token, i.e ETH decimals = 18; // Sets the number of decimal places uint256 _initialSupply = 1000000000; // Holds an initial supply of coins /* Sets the owner of the token to whoever deployed it */ owner = payable(msg.sender); balanceOf[owner] = _initialSupply; // Transfers all tokens to owner totalSupply = _initialSupply; // Sets the total supply of tokens /* Whenever tokens are created, burnt, or transfered, the Transfer event is fired */ emit Transfer(address(0), msg.sender, _initialSupply); }... code continues below (2)

We can now start defining the functions that are not automatically created for us. Remember, all public variables have getter functions defined automatically by Solidity 0.8 and above.

Over 200k developers use LogRocket to create better digital experiencesLearn more →

getOwner()

getOwner() returns the address of the owner of the BEP-20 token. It simply returns the owner variable we initialized in the constructor.

... code continues from above (2) function getOwner() public view returns (address) { return owner; }... code continues below (3)

transfer(address _to, uint256 _value)

transfer(address _to, uint256 _value) transfers a specified amount of tokens to an address. This function basically deducts an amount (_value) from whichever address called the function. The deducted amount is then added to the address specified in the argument (_to).

... code continues from above (3) function transfer(address _to, uint256 _value) public returns (bool success) { uint256 senderBalance = balanceOf[msg.sender]; uint256 receiverBalance = balanceOf[_to]; require(_to != address(0), "Receiver address invalid"); require(_value >= 0, "Value must be greater or equal to 0"); require(senderBalance > _value, "Not enough balance"); balanceOf[msg.sender] = senderBalance - _value; balanceOf[_to] = receiverBalance + _value; emit Transfer(msg.sender, _to, _value); return true; }... code continues below (4)

transferFrom(address _from, address _to, uint256 _value)

transferFrom(address _from, address _to, uint256 _value) transfers a specified amount of tokens from one address to another. This method differs from transfer in the sense that it allows an account to transfer tokens on behalf of another account.

To achieve this functionality, an allowance is approved by the recipient (_to) beforehand. All calls to this function then uses the preapproved allowance to make transfers.

An example use case of this method is a smart contract transferring tokens on your behalf and/or charging fees.

... code continues from above (4) function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { uint256 senderBalance = balanceOf[msg.sender]; uint256 fromAllowance = allowance\[_from\][msg.sender]; uint256 receiverBalance = balanceOf[_to]; require(_to != address(0), "Receiver address invalid"); require(_value >= 0, "Value must be greater or equal to 0"); require(senderBalance > _value, "Not enough balance"); require(fromAllowance >= _value, "Not enough allowance"); balanceOf[_from] = senderBalance - _value; balanceOf[_to] = receiverBalance + _value; allowance\[_from\][msg.sender] = fromAllowance - _value; emit Transfer(_from, _to, _value); return true; }... code continues below (5)

approve(address _spender, uint256 _value)

approve(address _spender, uint256 _value) allows an account (_spender) to withdraw from another account (the caller) multiple times, up to the specified amount (_value). This method is what makes transferFrom possible because an account is able to authorize another account to make transfers on its behalf.

... code continues from above (5) function approve(address _spender, uint256 _value) public returns (bool success) { require(_value > 0, "Value must be greater than 0"); allowance\[msg.sender\][_spender] = _value; emit Approve(msg.sender, _spender, _value); return true; }... code continues below (6)

mint(uint256 _amount)

mint(uint256 _amount) allows the token owner to create a specified amount (_amount) of new tokens and transfer them to themself. This increases the total supply of the token.

More great articles from LogRocket:

  • Don't miss a moment with The Replay, a curated newsletter from LogRocket
  • Learn how LogRocket's Galileo cuts through the noise to proactively resolve issues in your app
  • Use React's useEffect to optimize your application's performance
  • Switch between multiple versions of Node
  • Discover how to use the React children prop with TypeScript
  • Explore creating a custom mouse cursor with CSS
  • Advisory boards aren’t just for executives. Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.
... code continues from above (6) function mint(uint256 _amount) public returns (bool success) { require(msg.sender == owner, "Operation unauthorised"); totalSupply += _amount; balanceOf[msg.sender] += _amount; emit Transfer(address(0), msg.sender, _amount); return true; }... code continues below (7)

burn(uint256 _amount)

burn(uint256 _amount) allows a token holder to burn (i.e., destroy) a specified amount of existing tokens from their own account. This operation decreases the total supply of the token.

... code continues from above (7) function burn(uint256 _amount) public returns (bool success) { require(msg.sender != address(0), "Invalid burn recipient"); uint256 accountBalance = balanceOf[msg.sender]; require(accountBalance > _amount, "Burn amount exceeds balance"); balanceOf[msg.sender] -= _amount; totalSupply -= _amount; emit Transfer(msg.sender, address(0), _amount); return true; }... end of all code

Your source code should look exactly the same as the above.

Deploying the token contract using Remix

Now that we’re done coding the token, it’s time to deploy it. For this tutorial, we’ll deploy the token contract using Remix.

Before we get started, we need:

  • A browser with MetaMask installed so we can sign the transaction of deploying the token contract via Remix as well as interact with the token. Follow these instructions to set up MetaMask with the right Binance Smart Chain network
  • Some BNB to pay for the cost of deploying a new contract. If you’re deploying to the testnet, head over to the BSC testnet faucet and request some funds using the account you set up in the previous step. It might take a few seconds, but once you verify that you have some BNB via MetaMask, continue

Now that we have MetaMask configured and some BNB in our development account, we can go ahead and deploy the token contract to a public BSC network.

If you’ve been following this tutorial, then you already have Remix open. Otherwise, open Remix, create a new contract file, and paste in the contents of your token source code.

On the left sidebar, click on the Solidity compiler option (at the time of writing, it’s the second option), and click Compile Token.sol.

Click on the Deploy and run transactions option (third option).

Set the ENVIRONMENT to Injected Web3. A MetaMask prompt should pop up asking you to confirm the transaction. If it doesn’t, ensure you have MetaMask installed and configured on the right BSC network.

Click the Deploy button, confirm the transaction, and you should be able to see your contract under the Deployed Contracts section.

Copy the address of the deployed contract; you’ll need it in the next section. Simply click the Copy icon beside the deployed contract.

How to create and deploy a BEP-20 token to the Binance smart chain - LogRocket Blog (5)

Verifying and publishing your token contract on BscScan

Once you have your token deployed on a public network, you may want to verify the source code on BscScan.

BscScan is a tool that allows you to view transactions occurring on the BSC network (both mainnet and testnet). When you verify the source code on BscScan, you lend extra legitimacy to the token because it allows everyone to see what’s going on under the hood of the token.

Thankfully, doing this verification is relatively easy, as long as you have access to the source code.

First, let’s view the deployed contract on BscScan (full GIF walkthrough below).

Navigate to the homepage. If you deployed to mainnet, visit BscScan Mainnet. If you deployed to testnet, visit BscScan testnet.

Paste in the address of the deployed contract you copied from the previous step into the search bar and hit enter.

You should see details of the token. Click on the Contract tab below the token details.

Click Verify and Publish and fill in the form as shown below.

Make sure the compiler version is exactly the same as in Remix and that the license field is set to the same as in the source code (in this case, GNU Public License 3.0). Then, click Continue.

You should see an input box to paste in the contract smart code. Copy the source code from the Remix editor, paste it in the box, and click Verify and Publish.

How to create and deploy a BEP-20 token to the Binance smart chain - LogRocket Blog (6)

The token contract is now deployed and verified on BscScan, so it’s now possible to import the token in MetaMask and make transactions with it.

Now that the token contract is deployed on a public network, we can interact with it via MetaMask just like we would with any other token. However, there are a few steps to take before this is possible (full GIF walkthrough below).

First, open MetaMask and ensure that it is on the right network; it should be a Binance Smart Chain network.

Next, ensure that you’re using the same account that you deployed the token contract with. Also ensure that you’re on the Assets tab and then click Import tokens.

Paste in the deployed token contract address you copied earlier. MetaMask should read the token symbol and decimals automatically.

Click Add Custom Token and confirm the operation by clicking Import Tokens. That’s it!

How to create and deploy a BEP-20 token to the Binance smart chain - LogRocket Blog (7)

You should now be able to perform actions such as sending tokens to another address. The Swap functionality may or may not be available, depending on the network you’ve deployed to.

Conclusion and next steps

If you followed this tutorial all the way to the end, you should have a good understanding of the BEP-20 proposal, how to use Remix for coding and deployment, how to verify a token’s source code on BscScan, and how to import any token into MetaMask using the token address.

You can build on this knowledge by:

  • Implementing any additional custom functionality
  • Building a DApp to consume the token
  • Creating a liquidity pool for the token

Deploying a BEP-20 token on the Binance Smart Chain is not as difficult as you may imagine. I hope this tutorial helps you get started!

Join organizations like Bitso and Coinsquare who use LogRocket to proactively monitor their Web3 apps

Client-side issues that impact users’ ability to activate and transact in your apps can drastically affect your bottom line. If you’re interested in monitoring UX issues, automatically surfacing JavaScript errors, and tracking slow network requests and component load time, try LogRocket.https://logrocket.com/signup/

LogRocket is like a DVR for web and mobile apps, recording everything that happens in your web app or site. Instead of guessing why problems happen, you can aggregate and report on key frontend performance metrics, replay user sessions along with application state, log network requests, and automatically surface all errors.

Modernize how you debug web and mobile apps — Start monitoring for free.

How to create and deploy a BEP-20 token to the Binance smart chain - LogRocket Blog (2024)

FAQs

How do I create a BEP20 token on Binance Smart Chain? ›

The steps to create a BEP-20 token are:
  1. Defining Your Token's Purpose and Parameters.
  2. Setting Up Your Development Environment.
  3. Writing the Smart Contract.
  4. Testing the Token on a Testnet.
  5. Deploying the Smart Contract on Testnet.
  6. Final Review Before Mainnet Launch.
  7. Deploying the Token on Mainnet.
  8. Pre-Launch Checks.
Dec 2, 2023

How to deploy BEP20 token? ›

How to deploy BEP-20 token?
  1. Press the Add Token button at the bottom of the selected Metamask account.
  2. Fill in the token contract address. The token symbol and token name will automatically get detected. ...
  3. The token balance will appear when you click on Add Tokens to add the tokens to the Metamask account.

How much does it cost to create a BEP20 token? ›

Update & Maintenance
FactorsCost Estimation
Development Team$1000 – $1500
Complexity of Features$500 – $750
UI/UX Design$500 – $1000
Legal & Jurisdiction Compliance$600 – $1000
1 more row

How do I create a BEP20 token Binance Academy? ›

Can I create a token that rewards holders?
  1. Add the BSC Network to Your MetaMask Wallet: To create a BEP20 token, you first need to add the BNB Chain to your MetaMask or wallet. ...
  2. Connect Your Wallet to Token Tool: Token Tool is a platform that simplifies the process of creating and managing BEP20 tokens.

Does Binance Smart Chain support BEP20? ›

BEP-20 is a token standard on the Binance Smart Chain, similar to ERC-20 on Ethereum. It defines a set of rules that a token must follow to be considered BEP-20 compatible. This standard ensures compatibility between tokens and allows them to be easily stored and transferred using BEP-20 compatible wallets.

How to create BEP20 token for free? ›

How To Create BEP20 Token - Step By Step Guide
  1. Choose A Reliable Wallet. If you are determined to create a BEP20 token, you must choose a reliable crypto wallet. ...
  2. Set Wallet For Test Network. There are many test networks available on the internet. ...
  3. Write the Code For Token. ...
  4. Review and Deploy The Code. ...
  5. Test Your BEP20 Token.
Feb 27, 2024

How to launch a token on Binance Smart Chain? ›

Before going into detail, here is a short version of this "how to launch a token on BSC" guide:
  1. Set up a wallet extension and make sure to have tBNB;
  2. Connect your wallet to Remix;
  3. Create a smart contract for your token;
  4. Compile and then deploy your smart contract;
Mar 11, 2024

How much is the BEP20 token worth today? ›

The price of Sheesha Finance (BEP20) (SHEESHA) is $4.96 today with a 24-hour trading volume of $2.31. This represents a - price increase in the last 24 hours and a - price increase in the past 7 days. With a circulating supply of 59 Thousand SHEESHA, Sheesha Finance (BEP20) is valued at a market cap of $292,453.

How much does a BEP20 transfer cost? ›

Binance Smart Chain Network Fee
ActionNetwork feeConfirmation time
BNB transfer$0.01 = 0.000021 BNB~30 sec
BEP20 token transfer$0.03 = 0.000065 BNB~30 sec

How do I send my BEP20 token? ›

Sending BEP20 Tokens: To send BEP20 tokens from your Binance Smart Chain (BNB) account in Ledger Live, ensure you have BNB coins in the same account to cover the gas fees. Your parent Ethereum account must hold sufficient BNB to pay for the network fees associated with token transactions.

How to make BEP20 wallet? ›

How to get a BEP20 wallet
  1. Download and install Trust Wallet.
  2. Add BEP20 (BEP20) to your wallet.
  3. Access wallet features like buy, sell, swap and more.

How do I get BNB smart chain token? ›

You can buy BNB in the Bitcoin.com Wallet app in a few taps. Pay with credit card, bank transfer, or payment app and receive BNB directly in your self-custody wallet. BNB can also be purchased directly on this page and sent to the BNB Smart Chain wallet of your choice.

Top Articles
Solo 401k Plans For Multi-Member LLCs (Partnerships) - Carry
Is it safe to connect your wallet? | Insidor
Explore Tarot: Your Ultimate Tarot Cheat Sheet for Beginners
La connexion à Mon Compte
CKS is only available in the UK | NICE
Khatrimaza Movies
How Far Is Chattanooga From Here
Youtube Combe
Toonily The Carry
Housing Intranet Unt
A.e.a.o.n.m.s
Space Engineers Projector Orientation
Sitcoms Online Message Board
104 Presidential Ct Lafayette La 70503
Erin Kate Dolan Twitter
RBT Exam: What to Expect
Void Touched Curio
U/Apprenhensive_You8924
Nwi Arrests Lake County
VMware’s Partner Connect Program: an evolution of opportunities
Abby's Caribbean Cafe
St Clair County Mi Mugshots
kvoa.com | News 4 Tucson
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
City Of Durham Recycling Schedule
Marokko houdt honderden mensen tegen die illegaal grens met Spaanse stad Ceuta wilden oversteken
Narragansett Bay Cruising - A Complete Guide: Explore Newport, Providence & More
The Procurement Acronyms And Abbreviations That You Need To Know Short Forms Used In Procurement
Kaliii - Area Codes Lyrics
Stouffville Tribune (Stouffville, ON), March 27, 1947, p. 1
Kacey King Ranch
Datingscout Wantmatures
new haven free stuff - craigslist
Panchitos Harlingen Tx
Covalen hiring Ai Annotator - Dutch , Finnish, Japanese , Polish , Swedish in Dublin, County Dublin, Ireland | LinkedIn
The Complete Guide To The Infamous "imskirby Incident"
877-292-0545
A Comprehensive 360 Training Review (2021) — How Good Is It?
Scarlet Maiden F95Zone
Sdn Fertitta 2024
Charli D'amelio Bj
Mybiglots Net Associates
What Is The Optavia Diet—And How Does It Work?
Alba Baptista Bikini, Ethnicity, Marriage, Wedding, Father, Shower, Nazi
Craigslist Pet Phoenix
Motorcycles for Sale on Craigslist: The Ultimate Guide - First Republic Craigslist
SF bay area cars & trucks "chevrolet 50" - craigslist
Strawberry Lake Nd Cabins For Sale
Craigslist Cars And Trucks For Sale By Owner Indianapolis
Ippa 番号
How to Find Mugshots: 11 Steps (with Pictures) - wikiHow
Dr Seuss Star Bellied Sneetches Pdf
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated:

Views: 6200

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.