Smart contracts are integral in the functioning of Ethereum as a ‘programmable blockchain’.
These contracts are lines of code that ‘self-execute’ upon fulfilling a specific set of conditions.
Self-execute means executing without any third-party interference (as in on a blockchain).
Vitalik Buterin introduced the idea in the official Ethereum whitepaper in 2013. And, after 2015, independent developers started leveraging smart contracts to create their own tokens and crypto-assets.
Consequentially it led to 2017’s ICO boom. Three years later, writing smart contracts is still a valuable coding skill.
Or you may be looking to build a career as a professional blockchain developer. If it’s the latter, then you should make it a point to learn smart contract writing.
Overview of Smart Contracts, Source: DevTeam.Space
But before delving deeper to ‘solidify’ your ‘smart contracting’ skills, let’s take a look at a bit of history and working of smart contracts.
History of Smart Contracts
At that time he was a graduate student at the University of Washington.
Smart contracts also find mention in the Ricardian Contracts theory, an idea postulated by Ian Grigg and Gary Howland in 1996.
The Ricardian Contract Model, Source: Ian Grigg, Systemics Inc.
Ricardian Contracts were to act as a bridge between the usual text contracts and computer code.
Despite such notable mentions by such eminent computer scientists, smart contracts didn’t find takers until recently.
And due to their surging popularity, it makes sense to understand their working.
How do Smart Contracts Work?
Before discussing the technical aspects of how smart contracts work, let’s first look at an example.
Rajesh is a paper pulp processing factory owner in Noida. Naresh is a carton box manufacturer based in Surat. Rajesh and Naresh share a great business relationship. They trust each other and have been working with each other for quite a long time now.
Now imagine a scenario, where Naresh has a contract set up for placing orders to Rajesh for the raw material. Whenever the paper stock runs out at Naresh’s end, the system automatically raises an alert to Rajesh with more orders.
Rajesh fulfills the demand and collects the payment for the same through the same automated system. Business goes on as usual without any bottlenecks. This is just a visualization.
Since Ethereum is a public blockchain, all network participants (nodes) get notified about activities and transactions happening on the distributed ledger.
In Ethereum, smart contract execution happens on the Ethereum Virtual Machine (EVM). And every smart contract execution has to be paid for in ‘gas’.
Complex smart contracts (based on the transaction steps) need more gas for execution. The gas prevents overly complex or numerous smart contracts from overwhelming the EVM.
Working done. Now, let’s get to coding smart contracts!
How to Create and Deploy Smart Contracts?
Before progressing further let’s understand a bit about Solidity.
Typed statically, Solidity supports libraries, inheritance, and complex user-defined types.
A typical Solidity compiler converts a smart contract code into EVM bytecode, which in turn is sent to the Ethereum network as a deployment transaction.
Creating the smart contract
By default, your MetaMask wallet is connected to the main Ethereum network.
However, for writing smart contracts you must switch to any one of the displayed ‘test networks’:
- Ropsten Test Network
- Kovan Test Network
- Rinkeby Test Network
- Goerli Test Network
Check out this video below to set yourself up on the Rinkeby test network:
Next, you can go ahead and start writing your smart contract on Remix IDE (integrated development environment). It is a web-based decentralized application (dApp) and also functions through certain smart contracts.
For more information on writing code in Remix IDE, check out the video below:
Deploying the smart contract
After writing, now it’s time to deploy your smart contract!
You can also use real ETH for deploying your code. To buy Ethereum‘s cryptocurrency download the WazirX app on your phone, set up your account, and purchase ETH directly from the INR funds in your bank account.
After this, deposit the ETH you just bought into your MetaMask wallet.
Go to the Remix IDE, and click on the small ‘+’ sign aka ‘Create’ at the top left of your browser.
This will deploy your smart contract to Rinkeby, and confirm the transaction in MetaMask.
You have now successfully deployed your smart contract in the Rinkeby test network using MetaMask.
This was an overview of smart contract programming. There are lots of resources available on the internet that you can refer to. Here are a couple of them: