What are Smart Contracts?

A Smart contact is an agreement between two or more people in the form of computer code. They run on the blockchain, which mean that once a contract is deployed on the blockchain, it cannot be changed.The transactions that happen in a smart contract are processed by the blockchain,which eliminates the need of third parties to process these transactions.

Most of the tokens on the crypto market is built on the Ethereum platform, which means that those tokens are built using smart contracts which are deployed to the Ethereum network.

Today we will discuss how do smart contracts work on the Ethereum blockchain, from the moment they are deployed.

Deploying Smart Contracts

Ethereum Smart Contracts are coded in Solidity. and then to deploy the code on the Ethereum Network, the user has to pay an amount of ether which depends on the amount of code written and the amount of processing time that the contract takes.The contract is compiled into ‘bytecode’, which is a code that the ‘ethereum virtual machine’ (EVM) can read and execute. Ethereum runs smart contract code when a user or another contract sends it a message with enough transaction fees and when the contract is initially deployed.

Interacting With Smart Contracts

After a contract is deployed, the only way to deal with the contract is call one of it’s functions by generating a transaction that does so, we can do this by using MyEtherWallet and entering the contract address along with ABI which can be obtained from EtherScan if the contract is public.

For this example we will be using BNB Coin as an example to explain how interacting with the contracts work, BNB Coin Contract is public and can be read over here (0xB8c77482e45F1F44dE1745F52C74426C631bDD52)

As seen above, we can now interact with any method in the contract or get any variable in the contract such as the name,total supply,etc..

We will be interacting with the TransferTo method which is used to transfer a specific amount of BNB tokens from one address to another

The TransferTo method needs 2 parameters to be passed, the address and the amount we are transferring.

Depending on the method we are calling in every smart contract the amount of gas required for the transaction to complete will change. if the amount of gas provided is less than the amount of gas needed the transaction will fail due to running out of gas.

What happens when the transaction is sent to the transactions pool and then to each node is that the amount of gas provided is allocated to processing the contract transaction and when the transaction is processed the result is compared with another nodes to insure that it’s the same and then the address we transferred the tokens gets it when the next block is mined.

This is how all tokens on the Ethereum blockchain operate, with smart contracts. Other examples of Smart contracts on the Ethereum blockchain is an Exchange based on a smart contract (Etherdelta) and many others.

If you found this article any useful, you know what to do now. Hit that clap button and follow me to get more articles on your feed.