how to create your own cryptocurrency token

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. Bitcoin is the first-ever cryptocurrency created in 2009. Satoshi Nakamoto is the creator of Bitcoin.

Cryptocurrencies leverage blockchain technology. Blockchain is a decentralized network where no single authority controls the network. Blockchain is a kind of database that stores the data of the cryptocurrency. Computers participating in the network are called nodes of the network. These nodes are responsible for validating the data on the blockchain network.

Cryptocurrencies can have their own blockchain and they can also exist on other cryptocurrency's blockchain networks. For example, Bitcoin, Ethereum, Litecoin, Dogecoin, etc, have their own blockchain and the transaction data is stored on the respective blockchains. And cryptocurrencies like Basic Attention Token(BAT), LINK, UNI, SHIB are built on the Ethereum network, and cryptocurrencies like CAKE, BAKE are built on Binance Smart Chain.

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.

We have discussed that we can create a cryptocurrency token on another cryptocurrency's blockchain network, but not all cryptocurrency networks support building tokens on them. Ethereum is the first network to support smart contracts. Learn more about Ethereum, What is Ethereum? A Beginner's Guide

Earlier, we have seen How to create a smart contract on Ethereum network. Today, we will look into another popular blockchain namely Binance Smart Chain.  Binance 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.

remix connect to metamask





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. 

binance metamask




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. 




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. 


remix smart contract tutorial


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. 


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


bep20 smart contract


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. 


metamask bep20 bnb


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 and Ethereum Mainnet.  Verify it yourself by visiting below links. 





Next Steps!!

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

But for other people to use it, they have to buy for which you need to perform Initial Coin Offering and need to be listed on the exchanges. 

That is for another day. For now, go and share your BEP-20 verified Crypto token in your network. 

Also please do send your newly created tokens to our BEP 20 address   0xC9804b60c2A303d4664799a985e5088e4cE4C15C




Post a Comment

Previous Post Next Post