Use Promo Code ‘BLACKFRIDAY’ for 50% Off Your First Payment for Our Wealth Building Community Get Started!

In the age of smartphones and smart cars, Smart Contracts are somewhat of a contradiction of terms. There’s no artificial intelligence involved or required. This Smart connotation comes from how simple, functional and reliable these self-executing contracts are. Written in lines of code, they build on the blockchain principle of peer-to-peer interactions.

Smart Contracts are used for any number of agreements between individuals, organizations and institutions, including, but not limited to:

  •    Real estate agreements
  •    Auctions
  •    Human resources
  •    E-commerce
  •    Supply chain functionality
  •    Initial coin offerings (ICOs)
  •    Financial transactions (both fiat money and cryptocurrency)

 

Before we delve into how Smart Contracts work and how to set one up, let’s walk through the fundamentals of what blockchain is and how it works.

Blockchain is not an actual product, but rather a technology that was invented along with Bitcoin, the first prominent cryptocurrency.

Blockchain is a shared ledger used for recording the history of transactions. It cannot be altered and is transparent, meaning anyone with access to the ledger can review all transactions made on it.

Blockchain technology was an integral part of Bitcoin because it allows all Bitcoin holders to see when new Bitcoins are created or when they are sold or traded for other cryptocurrencies, for fiat money, or for other goods or services. Having a transparent ledger allows all parties to be aware of how much Bitcoin is currently worth on the open market.

Why the need for so much transparency? Consider a scenario where you’re a landlord renting an apartment to a new tenant. You require a deposit of $1,000 to give them the key so they can move in. They claim they’ve sent you a check in the mail and are demanding the key, but you haven’t received the check. It’s possible the check is lost or delayed, but your best business practices say they don’t get the key without the check. It leads to them unable to move in and bad feelings between the two of you from the get-go. They recorded writing a check in their ledger, but you haven’t received the money, so there’s no document of a deposit in your ledger. Two different ledgers, two different truths.

There is a single ledger in the blockchain, and all parties must give consensus before a new transaction is added to a network. Other members with access to a blockchain verify that any transaction occurred as said. Only then does that transaction become a part of the official record.

In general, blockchain transactions speed up the process dramatically because they are done entirely without paper. No more receipts, check stubs, check drafts, etc. Everything is done digitally, and the ‘receipt’ is permanently added to the blockchain. Disputes about payments and such are a thing of the past.

The blockchain is so named because each transaction is put into a ‘block’ as it occurs. The blocks are connected to each other in a row, giving them the appearance of being strung along in a chain. All blocks are encrypted, and the encryption is shared along the chain. That means that new transactions cannot be added without verification from all members of the chain.

More advanced blockchains say those used by enterprises, can have their parameters altered so that private parts of the blockchain require permission to access. The theory remains the same, and no transaction can be added to a block without the agreement of all stakeholders, but the actual transactions are partitioned on a need-to-know basis.

How Smart Contracts Work

Smart Contracts are built on logic. Because they are written in the blockchain, not only are they visible to all participants in the blockchain, but they are also nearly impossible to alter. The creator of a Smart Contract takes an item of value and transfers it into lines of code that form the contract’s program. The program runs the code but does not move the thing until its other party meets the conditions of the deal. Only then is the asset released. If the terms of the agreement are not met by a specific time, the item of value defaults back to the contract’s creator.

To illustrate this with a real-life example, imagine being a child at the grocery store and spying the bubblegum machine by the exit. The device has its Smart Contract in place – if you want a piece of gum, you’ve got to deposit a quarter into the slot and turn the crank to activate the mechanism that releases the candy. No other coin will work, not a nickel, not a penny, not the Canadian quarter your grandfather gave you that one time. And with its prominent location at the front of the store, the bubblegum machine is visible to almost everyone. If you tried to change the parameters of the contract – say by smashing the device on the floor – it would be evident to everyone and immediately labeled an illegal transaction.

What Your First Smart Contract Needs

A great place to build your first Smart Contract is Ethereum, which offers the chance to run contracts without “downtime, censorship, fraud or third-party interference.”

Ethereum offers an app called Ethereum Wallet which aids in the writing, deployment, and use of Smart Contracts.  It uses command line tools to create your contract and can also hold and secure cryptocurrency for use in said contracts. The language of choice for building Smart Contracts on Ethereum is Solidity.

As an example, let’s say Peter is a freelance website designer. He’s been hired by Lily, a self-employed businesswoman,  to create an E-commerce site for her boutique business of cat toys and accessories. Lily devises a Smart Contract in which she writes that Peter is to deliver a bug-free website design in four weeks’ time. Instead of traditional funds, Peter wants payment in Ether, the cryptocurrency whose blockchain is maintained by Ethereum.

Lily now must define two sets of variables to be included in the Smart Contracts code: functions and events.

Functions are the actions that the contract can take based on what is achieved or not achieved. If Peter submits the bug-free website inside of four weeks, the Smart Contract will transfer the agreed-upon amount of Ether to him. If he fails to meet the deadline or the work is not deemed acceptable by Lily, the balance of Ether in the Smart Contract will be returned to Lily. If Lily were using a third-party such as her bank or Paypal to send Peter payment for the job, there would also be functions in place to approve the transfer of said funds or return them via the third party.

Events are the actions that trigger functions in the Smart Contract. In Lily and Peter’s contract, there would likely be just one: Lily approving the website, which would trigger the transfer of the Ether to Peter’s account. The Smart Contract is over, both parties have what they wanted, and no intermediary is present to take a cut from both ends.

Smart Contracts can be as simple as the example above or as complex as you want them to be. Peter and Lily could agree to an arrangement with 25 milestones in which each time Peter submitted a bug-free page of Lily’s website; she released a portion of the overall payment to his Ethereum Wallet. With so many milestones in place, a Smart Contract would be an ideal way to keep track of how many pages Peter has finished, and how many payments Lily has released. Either or both parties could have faults in their ledgers, but the blockchain where their Smart Contract resides would have a perfect account of how many pages and how many payments.

 

About the Author

Daren is a cryptocurrency investor, miner, and blockchain developer. He researches the latest trends and technology in decentralized products and services.