Cryptocurrency Tokens
Binance Smart Chain is an Ethereum Virtual Machine(EVM) network which means every smart contract that executes on Ethereum main network also works on Binance Smart Chain. But why do we need an EVM-compatible network when we have Ethereum? Binance Smart Chain works on Proof of Stake consensus as opposed to Proof of Work on Ethereum. This makes transactions and execution of smart contracts cheaper compared to that on Ethereum.
While developers preferred Ethereum for their projects, BSC being EVM compatible is like an easy way to deploy their projects at much cheaper costs. Like Ether(ETH) is the native token on Ethereum, Binance Coin(BNB) is the native token on Binance Smart Chain. All the gas fees on BSC are paid using BNB. The daily transaction volume on BSC is much higher now than on Ethereum due to the lower transaction fees.
So if you are a developer who wants to get your token built on Binance Smart Chain, here is a walk-through on how to create a BEP20 token.
Contents
- Installing Remix IDE via Docker
- Creating Metamask wallet
- Solidity Smart Contract for your very own Cryptocurrency Token.
- Deploying the Smart Contract to Ropsten test network (Ethereum blockchain) with Metamask and Remix IDE.
- Getting our Source Code Verified on Etherscan
- Testing our Cryptocurrency by transferring it to Random Users.
Installing Remix IDE via Docker
docker pull remixproject/remix-ide:latest
docker run -p 8080:80 remixproject/remix-ide:latest
Creating a Metamask Wallet
Solidity Smart Contract for your very own Cryptocurrency Token
A smart contract consists of both variables and functions. Variables hold the state of a smart contract and functions dictate the behavior of the contract.
In the above contract, totalSupply is the total supply of your cryptocurrency, and balances mapping stores a map of address to token balance.
When the contract is deployed, the constructor is called and the initial supply was set to 21 million. And all the tokens are by default provided to the creator of the smart contract.
The name provided in the constructor will be the name of cryptocurrency and the same goes for the symbol as well.
The balance of function provides the balance of the PBT tokens at a particular address. The transfer function lets users transfer PBT tokens from one ERC-20 address to another. Both of these functions are used by an injected web3 provider like Metamask.
Below, we will see how can we transfer our tokens from one address to another.
Deploying the smart contract on Binance test network (BEP-20 standard)
The main difference between binance smart chain and ethereum mainnet is their proof of concept. Ethereum follows proof of work and binance follows proof of stake. So, the transaction fees are comparatively very lower on binance smart chain.
Like Ethereum, Binance has its own test network. To add this test network to metamask, follow this link - connecting binance test network and Main network to metamask.
Test networks are used to test the smart contract before deploying to the mainnet because it sucks to deploy directly on the main network by paying in bnb and watch it fail. So, heed the warning, always test the code, first on the test network before deploying on main net.
And also it doesn't cost us actual money to deploy and test on a test network
So, now copy the code above to the clipboard. Go to the Remix IDE tab which we opened after installing Remix IDE on the local machine or just go to http://localhost:8080
Right-click on contracts. You should see the below screen. Click on the new File and enter the name as Your token name.
In my case, it is PranayBathiniToken.sol
.sol is an extension for telling it is a smart contract written in solidity.
You can change the variable name to your own token name, the symbol, and total supply as well.
Now after making the changes, go to the compiler tab, select the compiler as 0.8.4 and click on compile as below. You should see a green tick mark upon successful compilation like below. It indicates we have the correct code in terms of syntax.
Binance Test Faucet - https://testnet.binance.org/faucet-smart
Go to the Activity tab like below and click on contract deployment - the contract we deployed just now.
You will see the below screen. Click on the arrow icon. It will redirect to binance testnet.
Now that the contract is deployed on the testnet. You can add the token to Metamask.
It is a two-step process.
- Copy the contract address which is the To address in the above image. (0xf60766025430b62e0465b2eaaa6dd3ab6cd83bdb)
- Go to Metamask, click on assets. Click on add token. Paste the contract address in the Token contract address section and the symbol name will be auto-populated like below.
Now, you can transfer your newly created cryptocurrency to anyone.
Getting your token on the main binance smart chain network
- Select Binance Smart Chain in networks in Metamask.
- Follow the same procedure mentioned above.
- It will cost you actual BNB to deploy the smart contract and make transactions instead of fake BNB which we obtained from a test faucet.
Special Note
We can use same solidity smart contract code for deploying on Binance Smart Chain and Ethereum Mainnet. Verify it yourself by visiting below links.
Post a Comment