What Are Smart Contracts and What Can They Do?

Understanding Smart Contracts is key to fully understand the impact of Blockchain in people’s lives.

Imagine a world where you no longer have to worry whether someone will pay you back on time because you would have engaged in an electronic agreement that will resolve all of this for you. Imagine a world where paper receipts are a thing of the past as all of your transaction items are associated with a protocol that’s tied to a ledger that you, the store, and your accountants share. Imagine a world where your property, both real and intellectual, is cataloged and title rights may be securely transferred remotely from anywhere in the world, but only with your expressed consent.

Have you ever said or heard a word so often that it obtains a meaning far grander than what its actual definition intends? Around October of 2015, I was discussing the implications of Ethereum as a blockchain technology and why it is important to a group of moderately tech-savvy friends. In the course of explaining Ethereum, I brought up the concept of “smart contracts”. One of the major disconnects I found was that my idea of a contract had begun to change and theirs hadn’t yet.

Growing up, watching TV and movies, listening to musicians, politicians, and businessmen speak, and hearing horror stories of legal situations gone wrong, the notion of a “contract” seemed like this large, monolithic set of documents. It was dense, it was hard to understand, you needed to really look over it with a fine-toothed comb for loopholes, and often loopholes could exist in law books you never even read. To some extent, that’s valid in certain cases.

Yet, have you ever asked yourself, “What is a contract… really?” Fortunately, you don’t have to, the answer is already defined for you:

1) n. an agreement with specific terms between two or more persons or entities in which there is a promise to do something in return for a valuable benefit known as consideration.

 The variations are almost limitless. Contracts for illegal purposes are not enforceable at law. 2) v. to enter into an agreement.

A smart contract is a set of executable protocols through which two or more parties may engage in agreements and value will be exchanged automatically by the terms outlined in said protocols. No third parties required. No escrow services required. No arbitration required. No courts required.

Don Tapscott speaks in length of the “Internet of Value” in his TED Talk, “How the blockchain is changing money and business,” and in more detail through his and Alexander Tapscott’s book, “Blockchain Revolution”. Vinay Gupta’s article, “What does $100 Ether mean?”, he defined a concept he calls the “Internet of Agreements”. Both men are positing similar propositions: The future of contracts will include some notion of autonomous code that, once mutually agreed upon, executes as conditions of the agreement are fulfilled.

Exchange will be simplified.

For smart contracts, the most apt method of value exchange is currently cryptocurrency. For those who do not know what cryptocurrency is, there are a myriad of articles that describe this subject already. I won’t go into the nitty-gritty details, but I will say that of the available cryptocurrencies, and there are many, Ethereum stands out as a platform because it is exclusively built for executing complex, Turing complete (programmable), smart contracts. For the remainder of this series, when speaking of smart contracts, it will be in the context of Ethereum and its capabilities.

Ethereum smart contracts are code. A reasonably seasoned developer can write smart contracts for the Ethereum blockchain in a Javascript-like language called Solidity. They are compiled to a special, very compact version of themselves called “bytecode”, and are then published onto the blockchain. Your contract is given its own address which you can share with other account holders. Using knowledge of the smart contract, these other accounts can choose to agree with and interact with your smart contract. Smart contracts can even interact with other smart contracts!

The cool thing about this is that, since it’s in the blockchain, every node on the blockchain network has a complete, compiled, bytecode copy of your smart contract. Each node has the Ethereum Virtual Machine (EVM) which can execute transactions on the network. Since the transactions are determined by the rules set forth in the smart contract, every node on the network is running all the smart contracts that anyone agrees to and interacts with via the blockchain.

“What if someone decides to run a really large program? Would an infinite loop bog down the network?”

Good question, Strawman! The solution that Vitalik Buterin had in his original white paper for Ethereum was that each operation on the EVM would have a price. This price, known as gas cost, would then be paid by the person requesting to interact with the smart contract using Ethereum’s cryptocurrency, Ether. The smart contract will execute on the EVM and the gas used to run the contract would be dispersed to the Ethereum nodes that executed the code. This limits the amount of calculations that can be spent on your contract, and if your contract is not efficient, then it could cost a pretty penny to run it. Gas price also fluctuates with miner demand. At the time of writing this, each unit of gas is 20 gwei (0.00000002 Ether).

“But, does that mean any contract can drain my account of Ether if it runs too long?”

Nope! When you execute the contract, you specify the maximum amount of Ether you’re willing to spend on gas costs. If the cost to execute extends past your budgeted gas limit, the execution is canceled, an out-of-gas error is returned, and the mining nodes get to keep the gas cost you spent. Your account will only be drained if your maximal gas allowed is equal to your account balance and you agree to a smart contract that will operate for that full amount. Even that isn’t likely to cost too much, as each block added onto the blockchain also has its own gas limit, thus preventing transactions that span multiple blocks. This block gas limit is determined by the miners and varies, but not by a wide degree.

“Can I use smart contracts as a big decentralized computer, like SETI@home? Can I store files in Ethereum?”

Maybe someday, Strawman. Gas costs are fairly prohibitive, as are the types of operations that can be executed on the chain. Soon there will be better ways, though. Ethereum projects such as Golem (a decentralized worldwide supercomputer) and Storj (encrypted file storage using the Ethereum blockchain) aim to bring the Ethereum chain closer to the dream of a worldwide computational network.

“Oh cool! What other projects can be built using smart contracts?”

Fantastic question! There’s a wide variety of apps already being built on the Ethereum protocol! For instance, there’s Gnosis, a prediction market platform. There’s Provenance, a system for providing supply chain transparency to enterprise businesses. There’s also Slock.it, which enables Internet of Things (IoT) communication via the blockchain using smart contracts.

Imagine a world where ordering a car to drive you to your desired destination no longer requires a service like Uber or a taxi corporation as the cab driver no longer needs these services to discover you and for them to operate as escrow to get paid. Imagine a world where a light goes out in your bathroom and the light fixture orders a new bulb on your behalf to be delivered to your door. Imagine a world where you no longer need a passport because your identity is stored, encrypted, in a decentralized blockchain to be verified by you on-demand.

The global impact of smart contracts will be astounding! However, it’s safe to say the technology is still in its early stages. There’s still a few hurdles to go past, such as transaction time, but there are solutions out there for many of these issues and it’s simply a matter of work to test and implement them. Until then, support these projects, and keep your eyes to the future.

I hope this helps someone!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.