Smart Contract – Introduction


Smart contracts were introduced with the launch of Ethereum in 2014. It contains a piece of code which will execute in a certain way once the conditions are met.

The basic contract is simple and only defines the the framework for the Token it represents. The easiest tool to work with when writing smart contracts is Remix¹ so we will use that.

Before we start with the actual contract we need to get a wallet² and some crypto³

When using Remix the Metamask wallet is preferred. Follow the instructions at their website in order to install the wallet.

The Metamask wallet works as an extension in your web browser (i.e Chrome, Firefox etc).

We will work on Binance blockchain, but everything we do on Binance blockchain also works on the Ethereum blockchain. If you wish to launch a live contract, you need to get some Binance coins.

Screenshot of Remix

Simple Smart Contract

Screenshot of Remix

Part 1

Here you name your contract, we call our contract “NewToken”. The name of the Token is “N00B”, it’s symbol is NUB, it has 18 decimals and a total supply of 1 billion that will be sent to the owner upon deployment.

Screenshot of Remix

Part 2

These functions makes the balances public and regulate the way transactions are handled. Such as removing tokens from the sender, and adding tokens to the reciever, and gives an error message if funds are missing.

Screenshot of Remix

Part 3

These last functions handles the rules for allowances, i.e allowing another account to spend tokens on your behalf. The balance of how much the “spender” have spent and how much is left to spend will be set here

SPDX-Licence-Identifier: GPL-3.0

This shows how the code is licensed and how it might be used. GPL-3.0 means the code is free to use, copy and distribute but can not be changed.

Screenshot of Remix

pragma solidity ^0.8.0

This tells Remix which version of the compiler it should use to compile your code. ^0.8.0 means the compiler needs to be version 0.8.0 or later.

Compiling the code in Remix

Screenshot of Remix

The interface of Remix is intuitive and easy to use. When you open it, it will have a few sample files. You can delete them or keep them, it doesn’t matter which.

Screenshot of Remix

When you right click at the top folder named “contracts”, you can an option to create a new file. You can name it whatever you like, just make sure that it ends with .sol.

For this example I have named my file to NewToken.sol. Once you’ve named your file, a new window opens in Remix. This is where you will add your code.

Screenshot of Remix

The .sol file extension is needed for Remix to understand that the programming language that is used is “Solidity”.

If you type the code manually in Remix, make sure that you haven’t missed anything. Any line that starts with “// ” is ignored by Remix, and you can remove them if you wish. You can also write your own notes by adding // in front of the note.

Note: The complete code can be found here

Screenshot of Remix

Once the code is added in Remix, it’s time to compile it all.

The compiler is opened by selecting the compiler icon (marked red on the image).

Because we specified the compiler version on the second row of our code, we don’t need to change anything at this moment. Just press the compile button at the bottom.

You will know that everything was done correctly if you don’t get any error messages, and there’s now a green tick on the compiler icon.

You will then find the deployment menu right underneath the button you used to access the compiler.

At this point you need to have Metamask installed, and some Binance coins (BNB) in your wallet. Alternatively you can use Binance test chain, as well as Binance test coins (tBNB). Using the test chain is great for testing new contracts, as it doesn’t cost you anything in gas price.

The Metamask wallet is set to Ethereum blockchain as default, which means you need to set it up to work on Binance blockchain.

Open Metamask and go to settings and then network. Choose “Add new network”. Then you will need to add both the main and test networks.

Add the two networks by copying the settings from the image below.

Screenshot of Remix
Screenshot of Metamask
Deploying your Smart Contract

Now we are ready to deploy our contract. Make sure that the deployment menu looks like it does on the image. The enviroment should be Injected Web3 and the contract should say NewToken – contracts/NewToken.sol.

Injected Web3 means that you will be using Metamask to deploy the contract. Where it says “Account” is where your (truncated) address is, the rest isn’t anything we need to worry about at this point.

When you press the “Deploy” button, Metamask will pop-up and ask you to confirm the transaction. Once the transaction is confirmed, you will get additional information at the bottom of the screen in Remix.

Screenshot of Remix

In the right field at the bottom of the screen in Remix you will see the transaction hash, the account that deployed the contract, the name of the contract and the amount of gas that was used during the deployment.

Next you should copy the transaction has and paste it in Binance blockchain explorer. This will show similar information as in Remix.

Click at the token name (in this case N00B (NUB))

Screenshot of crypto transaction
Screenshot of crypto transaction

By now you might have noticed that your new tokens are missing from your wallet. If you haven’t already, go and check. Often you need to manually add new tokens to Metamask for it to show up.

Often it is enough to just provide the contract address. Paste the contract address and then press “Add custom token”. Now you have 1 billion N00Bs in your wallet!

Screenshot of Metamask

There you have it, your very own cryptocurrency!

Remember, if you wish to deploy your coin at the main net you need to get some real Binance coins. You can buy Binance coins and other cryptocurrencies at the following exchanges.

Check out the guide for writing a smart contract for a crypto faucet: Crypto Distribution – Faucet

Promoted Exchanges

Note: Investing and trading with cryptocurrencies can result in significant loss

Binance and offer everything you need, along with a $20 welcome bonus.


BitPanda is the easiest cryptotrading platform, and perfect for the beginner.

ExpressVPN is the fastest and most secure on the market. Try it for FREE for 30 days!