Blockchain Tutorial,Milestone #4 & 5: Get Educated On Smart Contracts
How do you define a smart contract?
According to Wikipedia, a smart contract is “a computer protocol intended to facilitate, verify, or enforce the negotiation or performance of a contract”. While it was first proposed by American cryptographer Nick Szabo in 1996, Ethereum is often credited with popularizing the concept and making it mainstream.
So, what are the desirable properties that we want in our smart contract?
Anything that runs on a blockchain needs to be immutable and must have the ability to run through multiple nodes without compromising on its integrity. As a result of which, smart contract functionality needs to be three things:
Feature #1: Deterministic
A program is deterministic if it gives the same output to a given input every single time. Eg. If 3+1 = 4 then 3+1 will ALWAYS be 4 (assuming the same base). So when a program gives the same output to the same set of inputs in different computers, the program is called deterministic.
There are various moments when a program can act in an un-deterministic manner:
- Calling un-deterministic system functions: When a programmer calls an un-deterministic function in their program.
- Un-deterministic data resources: If a program acquires data during runtime and that data source is un-deterministic then the program becomes un-deterministic. Eg. Suppose a program that acquires the top 10 google searches of a particular query. The list may keep changing.
- Dynamic Calls: When a program calls the second program it is called dynamic calling. Since the call target is determined only during execution, it is un-deterministic in nature.
Feature #2: Terminable
In mathematical logic, we have an error called “halting problem”. Basically, it states that there is an inability to know whether or not a given program can execute its function in a time limit. In 1936, Alan Turing deduced, using Cantor’s Diagonal Problem, that there is no way to know whether a given program can finish in a time limit or not.
This is obviously a problem with smart contracts because, contracts by definition, must be capable of termination within a given time limit. There are some measures taken to ensure that there is a way to externally “kill” the contract and to not enter into an endless loop which will drain resources:
- Turing Incompleteness: A Turing Incomplete blockchain will have limited functionality and not be capable of making jumps and/or loops. Hence they can’t enter an endless loop.
- Step and Fee Meter: A program can simply keep track of the number “steps” it has taken, i.e. the number of instructions it has executed, and then terminate once a particular step count has been executed.Another method is the Fee meter. Here the contracts are executed with a pre-paid fee. Every instruction execution requires a particular amount of fee. If the fee spent exceeds the pre-paid fee then the contract is terminated.
- Timer: Here a pre-determined timer is kept. If the contract execution exceeds the time-limit then it is externally aborted.
Feature #3: Isolated
In a blockchain, anyone and everyone can upload a smart contract. However, because of this the contracts may, knowingly and unknowingly contain virus and bugs. If the contract is not isolated, this may hamper the whole system. Hence, it is critical for a contract to be kept isolated in a sandbox to save the entire ecosystem from any negative effects.
Now that we have seen these features, it is important to know how they are executed. Usually the smart contracts are run using one of the two systems:
- Virtual Machines: Ethereum uses this.
- Docker: Fabric uses this.
Let’s compare these two and determine which makes for a better ecosystem. For simplicity’s sake, we are going to compare Ethereum (Virtual Machine) to Fabric (Docker).
If you are interested in Ethereum development specifically then it is important that you learn solidity as well.
For anyone who wants learn how to make DAPPs (Decentralized Applications) or get into the ICO game, learning Solidity is an absolute must. Here we are going to give you a basic overview. Solidity was developed by Gavin Wood, Christian Reitwiessner, Alex Beregszaszi, Yoichi Hirai and several former Ethereum core contributors to enable writing smart contracts on blockchain platforms such as Ethereum.
So, let’s see the action steps now:
- Understand how smart contracts work.
- (Optional for Ethereum developers) Learn Solidity.
Milestone #5: Be In The Mix
One of the most important things that you can do as a budding developer is to constantly stay in the mix.
Go and join the Reddit forums, Gitbub pages, and StackExchange and connect with other developers and always be on the lookout for any news regarding the technology.
Along with that, it will be helpful for you to know what people look for in blockchain developer. What qualities are companies looking for when they are looking to hire?
This information can be very useful in you fine-tuning your skills enough to appeal to the companies.
So, this is a rough roadmap for you and your journey to becoming a blockchain developer. This alone won’t be enough, of course, you will need to show your own initiative and always be in the mix.