Smart Contracts and the Blockchain
Blockchain is a chain of blocks. Simple as that. How can you make smart contracts out that phenomenon, everybody is currently talking about?
A blockchain, in its core, is a distributed database where every node contains the full information of the whole database. So, every node can validate the consistency of the database in total. The blockchain is a true expression of the peer to peer principle, a system regulated equally by all participants and not by a central authority. There is no central copy of the database as an official reference you could trust in. But you can trust in the distributed similarity of the originals at every peer or node (decentralized consensus).
A block is a record in this database, containing individual data sets. Every block is directly linked to the predecessor block, creating a distinct line of development within the database – like a chain. This link is made by including the hash value of the previous block (which is represented in the header of this block) into the new block. Consequently, you cannot alter any block in the chain without corrupting the integrity of the database – you will break the links. You can compare that to the classical journal in accounting.
The creation of blocks, i.e. inclusion of new data sets into the database, is called mining. This refers to the first application of the blockchain principle in the fields of crypto currencies (Bitcoin). With that operation, new currency or a transaction of such (as a database entry) was created. The miner is awarded with a certain amount of such crypto currency for its computing work. But why is it work at all? Because, as well resulting from the first application, it should be reached with efforts only, be rare and therefore creating an artificial value, then represented in the crypto currency. In such applications, the data sets of the database are transactions between users. Such could be my account value, me transferring one Bitcoin to a friend’s account, and his new account value.
These transactions are now put into the database by creating a new block. This block always contains valid transactions only. To create the needed work effort, the miner now must solve a given task by the system (“proof-of-work” principle). The proof-of-work principle also safeguards the blockchain database as a publicly open system from spam transactions/spam data entries, because it does not make sense to spend such efforts on creating spam. At Bitcoin, this task is, that the new hash to be created shall be at or below a given target value determined by the system. The miner has to vary parameters of the data set of the transactions as long as he has not met this target. This is why the data contains a kind of blank field, which can be varied as needed (the “nonce”, basically being incremented in every attempt of creating a block and then totally varying the hash). The computing work has some similarity to a lottery. Once you hit the target or below, you created a new block, then accepted by the system and you are rewarded in crypto currency for that work. In Bitcoin for instance, that means that a transaction needs significant time to be executed, resulting from the time to find somebody to do this work and the time he needs to hit the target. To improve your position in the waiting line you could offer more Bitcoin rewards for the transaction.
Now think of a situation where you own a photo voltaic installation on your dwelling and you and your neighbor bought together a battery storage. You agreed that your PV system shall charge the storage every time it offers excess electricity exceeding your consumption and the storage shall supply you both at night, when energy is needed and no sun is shining. You both determined prices for supplying the electricity to the storage and for delivering out of the storage again, reflecting the PV installation and operation cost, which occur at your side only and the shared procurement cost for the storage. The whole supply and the transactions shall be done automatically. You do not want to involve neither a bank nor a utility in its classical, centralized roles. This should be a perfect example for a smart contract system based on the blockchain.
The Bitcoin protocol, operating the Bitcoin blockchain, was just designed for the sole purpose of creating a crypto currency. It is considered a very simple and restricted protocol. In our example, it would be needed that we are absolutely clear at what time we had excess energy in the PV system, when was how much consumption etc. This is all basically data appropriate to be stored in a database. But the Bitcoin protocol would not be able to handle that. However, next to Bitcoin, other blockchain protocols are being developed. One example is Ethereum. It also contains a crypto currency token (the Ether), but has a much broader protocol, too. The Ether is used to pay for transaction fees and computational services on the Ethereum network.
The Ethereum project developed scripting functionalities which can be utilized to form smart contracts. The contracts are programmed in special languages and are then stored in the blockchain. The Ethereum blockchain can execute these contracts as transactions. The downside is that, as the blockchain principle, every node has to execute each available contract in parallel, reducing the network performance, as every contract may contain several transactions. A blockchain-based smart contract is visible to all users of said blockchain. Otherwise, the validation peer-to-peer would not be possible. The crypto currency is a transaction trigger in this regard, like a tip you give to a porter to open a door. But this should be less than you pay to a bank for a transaction.
With the right programming skills, the availability of excess electricity could trigger a delivery contract in the Ethereum blockchain for charging the storage, then facilitating automatic Ether payment to your account. The same with the usage of the storage to supply yours and your neighbor’s house at night. You can trust each other, as you can check everything in the blockchain. And: taking in the new neighbor will be as easy as that.
Quite smart, isn’t it?