There are so many blockchains out there, which one do you choose?
Well the infamous Bitcoin isn’t the most interesting to be quite frank, it’s missing the concept of smart contracts. Then there is the legendary Ethereum; the first to have smart contracts and for a long time it was most active but it became a victim of its own success and fairly recently Binance Smart chain overtook it. Ethereum couldn’t scale its technology to support it’s growing number of users and the transaction fees known as gas fees escalated.
Smart contracts are little programs that run on the blockchain and are written in a programming language called Solidity, check out https://remix.ethereum.org to get going. So the good news is that if you know how to code you could be on the verge of creating your own cryptocurrency.
So enter Binance Smart Chain, but how does it work?
It’s essentially a copy paste of ethereum with the subtle difference of the miners being pre approved. Therefore in essence it’s not a true blockchain because it’s centralised.
It consists of a network of computers, each one running a node and tokens are created on demand at any time.
Binance smart chain has issued its own native token called BNB but fortunately you can create your own.
How do you go about that?
We won’t cover everything here but a concept that it’s interesting to introduce is ERC20.
In order to create your own token you have to conform to certain standards and one of the most popular of these is the ERC20 which introduces a standard for Fungible Tokens.
Using the ERC-20 standard ensures that a token is compliant for the following use cases (and more):
- Wallet transfers — sending tokens from one account to another
- Buying and selling on cryptocurrency exchanges
- Purchasing tokens in an crowd sale (ICO), this is one for another post
The ERC-20 specification essentially dictates the interface that the smart contract must respond to. It specifies the structure of the smart contract and types of functions that the smart contract must have. It also provides some suggested functions that are nice to have, but ultimately optional. It dictates certain events that our token must have, like a transfer event. Smart contracts can emit events that consumers can subscribe to, and with this standard, we can subscribe to events that tell us when tokens are sold.
Here is an example implementation of the transfer function specified by the ERC-20 standard. It is required by the smart contract, and governs how someone can send an ERC-20 token from their wallet to another.
Here’s a simple example:
This function implements the ERC-20 standard the following ways:
- It has a transfer function.
- It accepts the correct arguments.
- It fails if the user doesn’t have enough tokens to transfer, i.e., an insufficient balance.
- It transfers the balance from the sender’s account to the receiver’s account.
- It triggers a sell event.
- It returns the correct value, e.g., true.
Be careful though with whatever you deploy, once your smart contract is deployed, it’s there forever and there is no going back. Make sure to use a good testing framework like what you get with Truffle