How To Create Your Own Cryptocurrency on Binance Smart Chain

Do repost and rate:

      A cryptocurrency is basically a form of digital cash or a digital currency. A currency acts as a medium of exchange and a digital currency is a digital medium of exchange. Cryptocurrencies are a digital medium of exchange.  

Cryptocurrency Tokens

Cryptocurrencies that are built on top of other cryptocurrency blockchains are called Tokens/Cryptocurrency Tokens. All the data of a token whether it is transactional data or smart contract data exists on the blockchain on which they are built. All tokens are cryptocurrencies but all cryptocurrencies are not tokens.   Earlier, we have seen How to create a smart contract on Ethereum network. Today, we will look into another popular blockchain namely Binance Smart ChainBINANCE Smart Chain tokens are known as BEP-20 Tokens. In this article, we will show you how to create your very own cryptocurrency(BEP-20 token) on Binance smart chain using Solidity.   Why Binance Smart Chain(BSC)?

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 installation process is very simple. If you don't have docker installed, install it from here. Trust me docker will save a lot of valuable time which we are going to lose in the installation process and configuration.    Once you have installed docker and running it, execute the below command.   

docker pull remixproject/remix-ide:latest

 This command will pull the latest version of IDE into your system. Now let's run it. Execute the below command to run it.  

docker run -p 8080:80 remixproject/remix-ide:latest

Now your IDE is running. Go to http://localhost:8080 and you can use your Remix instance.  You should be able to see a screen like below.

If you are not interested in installing docker or facing any issues while downloading it, you can use online version of remix IDE - https://remix.ethereum.org  for the next steps in this blog. However it is recommended to have an offline version for actual development.     

 

Creating a Metamask Wallet

  Metamask is a web-based Ethereum wallet. It is available as an extension. We can store all kinds of Ethereum-based tokens on Metamask. After creation, we will get our own private keys and an ERC-20 address.    Add to chrome or BRAVE from here.  You can follow this article on how to create an ethereum wallet using metamask.   Once you follow all the steps, you will have an ERC-20 Address like below.     

 

Solidity Smart Contract for your very own Cryptocurrency Token

Now, all we need is a solidity smart contract. A Smart contract is a piece of code uploaded to the blockchain. The code will contain public functions which can be called by anyone connected to the blockchain from their computer.    Refer to this article on Solidity( a programming language to write smart contracts) and smart contracts to get a basic understanding.     Below is the code for your own cryptocurrency token. It is written to be compatible with the 0.8.4 version of solidity.   

// SPDX-License-Identifier: GPL-3.0pragma solidity ^0.8.4;contract PranayBathiniToken {    mapping (address => uint256) balances;    uint256 public totalSupply ;        // Optional params    string public name;                     uint8 public decimals;                    string public symbol;                    string public version = 'V.1.0';           constructor() {        balances[msg.sender] = 21000000;                       name = "Pranay Bathini Token";             totalSupply=21000000;        decimals = 0;                                   symbol = "PBT";                                 }    function balanceOf(address _owner) public view  returns (uint256 balance) {        return balances[_owner];    }        function transfer(address _to, uint256 _value) public  returns (bool success) {        if (balances[msg.sender] >= _value && _value > 0) {            balances[msg.sender] -= _value;            balances[_to] += _value;            emit Transfer(msg.sender, _to, _value);            return true;        } else { return false; }    }        event Transfer(address indexed _from, address indexed _to, uint256 _value);}

 

 

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. 

 

Now, let's go to Deploy and Run Transactions tab. By default, you should see the environment as Javascript VM.    According to the docs, If you deploy on this environment, all the transactions will be executed in a sandbox blockchain in the browser. This means nothing will be persisted when you reload the page. The JsVM is its own blockchain and on each reload it will start a new blockchain, the old one will not be saved.   Instead, we will use Injected Web3 as an environment. The Remix IDE will connect to metamask. Click on Next and continue.    Switch the Network from Ethereum Mainnet to Binance Testnet in metamask.   Get some test BNB for deploying from the below faucet.   

Binance Test Faucet - https://testnet.binance.org/faucet-smart

  Now, we have some test ether.  Let's deploy to the test net. Click on Deploy button. Metamask will ask for confirmation. Click on next and deploy.  The smart contract will be deployed on Binance Smart Chain test network.  

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 

  All the steps mentioned above will be the same except in the network section -   

  • 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

  Now, we can get our smart contract verified on bscscan by visiting the contract tab of our contract address and submitting our smart contract code. Read about how to get our smart contract verified for more information.

We can use same solidity smart contract code for deploying on Binance Smart Chain(BSC) and Ethereum Mainnet as BSC is ethereum compatible. Only difference is BSC proof of concept is Proof of staked Authority and Ethereum proof of concept is proof of work. Transactions are much cheaper on BSC.

 

 

Next Steps!!

 

Congratulations !!!  Now you have your own cryptocurrency token on the BEP 20 token which other people can use for transactions.   

PS

This blog is a repost from my crypto blog - www.thecryptoinsight.com. The smart contract used in this blog is not audited and  to be used only for learning purpose. 

 

Thanks for reading.

 

 

Regulation and Society adoption

Ждем новостей

Нет новых страниц

Следующая новость