Smart contracts — The Jewel of Blockchain?

Yuri Luiz de Oliveira
WAES
Published in
10 min readSep 17, 2022

You probably heard this term even if you’re not a Web3 enthusiast. Smart contracts are essential to the third revolution in the World Wide Web because they expand the potential of Blockchains. This technology is commonly associated with Bitcoin, but this network can only be used to transfer Bitcoin funds from one wallet to another.

If you think about it, transferring funds between wallets is nothing but a contract where one party agrees to send money to another one. And usually, financial transactions are bound to something else, like the transfer of ownership of an asset.

Bitcoin cannot provide that via smart contracts, but other Blockchains are.

What are smart contracts?

The name is self-explanatory: they are contracts with some “intelligence”. But what does it mean exactly?

Imagine if you could bind the transfer of funds to the whole chain of agreements between parties. For example, when funds are sent from A to B, the asset from B is automatically transferred to A. Smart contracts provide that level of intelligence to a contract.

Simply put, smart contracts are computer programs that run in a blockchain when specific conditions happen. They’re commonly used to transfer funds from one wallet to another. They’re run in a decentralized way, implying that their execution is transparent and auditable.

A smart contract within a Blockchain

How do smart contracts work?

Think of a conventional contract. It is a piece of paper (or digital document) containing one or more agreements between two or more parts. It includes clauses that define the obligations and rights of each party.

Conventional contract

A rent contract, for example, contains the price and date agreed for the monthly payment. If the rent contract is not smart, humans must enforce the clauses. E.g., the tenants must manually transfer the money to the landlords’ accounts every month before a specific date. They depend on humans’ actions to be respected. It might lead to things like:

  • Tenants forget to pay the rent on the agreed date.
  • Tenants don’t pay the rent on purpose.

The tenants make a rent payment, and they might decide not to proceed with the payment. In conventional contracts, there’s no way for the landlords to force the tenants to pay other than using the law.

In smart contracts, since the contract assures the payment, the funds would automatically be transferred if all conditions were met (i.e., the due date is current or in the past, and the transfer has not yet been done). This means that the parties involved don’t have to trust each other: the tenants don’t need to trust the landlord, and the landlords don’t need to trust the tenants.

Smart contracts - Image by macrovector on Freepik

How are smart contracts run?

Most systems nowadays are controlled and run by some infrastructure managed by the same company that developed the system. These systems tend to be very isolated from the external world, having small interfaces with the outside. In most cases, we don’t know what happens inside it and how much we can trust it. This is known as a centralized model.

There are a lot of mechanisms to achieve isolation, for example, having an enterprise gateway that authenticates every request. The gateway is hosted within a cloud provider with many other security measures like firewalls, access lists, and virtual private clouds. That is all to ensure no unwanted access happens (yet it often occurs). We spend a lot of time and money to have some peace of mind.

What if I told you that smart contracts are usually run on computers we have no control over? We have no idea where it is in the world or which software it has installed. Would you trust it to run your smart contract code?

What if I told you that you could trust that the code execution is safe and it’s virtually impossible to corrupt the result?

Exactly how smart contracts are run depends on the blockchain network. But they all share some common characteristics. In general, the execution can be summarized as:

  1. Multiple nodes that have the blockchain client installed pick up the contract execution. Those nodes might be a personal computer in Brazil, a Linux instance running in AWS’ us-east-1 region, a computational rig based in China, or any computer with the blockchain client installed.
  2. They will execute the code separately and share the result they computed. Code execution is isolated via virtualization. Ethereum has EVMs (Ethereum Virtual Machines), while Hyperledger Fabric uses Docker containers.
  3. The nodes will achieve consensus on the valid result of the execution. Note that if one node manipulates the result, all other nodes would have to do the same and agree on the same result. The decentralized nature of blockchains makes it nearly impossible to happen.
  4. When the result is agreed upon, it will be written into the blockchain history.

In exchange for the processing power provided to run the smart contract code, they will be rewarded with something. In Ethereum, they are rewarded in Ethereum’s token Ether.

Use cases

The possibilities are countless. It only depends on the creativity of the smart contract developers. The following are some of the most well-known use cases for smart contracts.

Finance

Cryptocurrencies are the most mainstream use case of blockchains. By running in the blockchain, smart contracts can easily manage funds, enabling automated transfers, borderless transactions, keeping records, and many other financial uses.

Tokenization

The representation of assets as tokens in the blockchain. This process is used to ensure the ownership of the assets. Tokenization enables shared ownership, for example. The most straightforward use of tokenization is in the real state, where more than one person can own a property. E.g., the other of a part of a property may decide to sell their part without the need to sell the whole property.

Voting

As blockchain is decentralized, they are transparent and auditable. Anyone with enough knowledge of the blockchain can audit the votes. More importantly, since it’s complicated to track a person by their identity (address) in the blockchain, it is virtually impossible to connect a specific vote to its voter.

Healthcare

In a blockchain, the data owners are those to whom the information belongs. It means that the medical records are controlled by yourself. It means that you choose what to share with whom. And the information is not bound to the system of a specific doctor, hospital, or insurance company.

Benefits

Security

Blockchains are highly secure. It’s virtually impossible to perform actions in someone else's name or rewrite the blockchain history. The weakest link in the blockchain is usually the humans that use its applications.

Automation

As smart contracts are pieces of code that run in the blockchain, their execution is automated. No human action is necessary to enforce the execution of the contract. It makes smart contracts faster and less error-prone.

Clearness and transparency

The contract is described by its code. Programming language is objective. It’s not open to interpretation. It does not matter if the person reading it is a lawyer or not. Given the same condition, the outcome of the contract is always the same.

Trustless

It might seem weird to add “trustless” as one of the benefits if you think about it, although in conventional contracts, you must trust everyone involved in it. On the other hand, when the execution of the contract is automated, you don’t need to trust anyone. For example, if you’re selling something, you are sure that the asset ownership will be transferred only if you receive the agreed amount.

Auditing

By design, Everything that happens in the blockchain is registered. Anything is only valid when it’s been added to a block, and the block is added to the blockchain. It means it is possible to trace back all the things that previously happened in that blockchain. To achieve the same result in conventional contracts, there would need to input records manually.

Drawbacks

Comprehension

As mentioned in the benefits, smart contracts are not open to interpretation, and they’re bound to the contract’s code, which is good. However, to understand what happens when the contract is executed, it’s necessary to have technical knowledge of the language in which the contract was written. Programmers are familiar with how a messy codebase can be harmful 😅.

Bugs

Software developers sometimes make mistakes. Bugs in the contract code or in the blockchain might lead to unexpected behavior. Funds could be lost, for example. And some failures are not reversible. An active community is critical to guarantee that smart contracts are appropriately tested and flaws are reported and fixed quickly.

Regulations

The regulations surrounding blockchain and cryptocurrencies are still unclear and volatile. Different countries might have other laws according to smart contracts, and rules can change quickly.

Flexibility

Again, smart contracts’ execution is automated. But, in some cases, it might be interesting for the involved parties for the contract to be flexible. However, achieving such flexibility may be problematic when the contract is active if it is not part of the contract in advance. It could cause smart contracts not to be a good choice for every occasion.

Popular smart contract platforms

Just like conventional systems, there are numerous options when it comes to running smart contracts. Each platform has its particularities, and choosing an appropriate platform is essential to develop successful smart contracts.

The following are some of the most popular platforms. Some are simpler. Others support more popular programming languages or runtimes.

Ethereum

Ethereum has the most valuable token among smart contract platforms: Ether. It’s public and open source. It currently uses proof of work consensus and will use proof of stake after The Merge.

The main programming languages of this platform are Solidity and Vyper. They run within EVMs (Ethereum Virtual Machines). EVMs are powered by Gas (i.e., executing smart contracts within Ethereum costs Gas).

Hyperledger Fabric

Hyperledger Fabric is a distributed ledger (not really a blockchain) created by the Linux Foundation. It is an authenticated permissioned platform, making it suitable for use cases where security and authorization are necessary. Hyperledger is focused on providing a platform for enterprise-grade applications blockchain projects.

It doesn’t achieve consensus by PoW or PoS, the most common consensus mechanism. According to its documentation, the transaction has a flow of five steps. The steps are described in Hyperledger Fabric’s documentation.

It supports Go, JavaScript, and Java code within docker containers. The advantage is that those languages are highly spread among software developers, and docker is widely used in cloud applications.

Polkadot

Polkadot is a network protocol that provides the ability to transfer any data between different types of blockchains. It allows data to be shared between public, open, permissionless, permissioned, or private blockchains.

Polkadot’s website exemplifies that, for instance, a school’s private, permissioned academic records chain could send proof to a degree-verification smart contract on a public chain.

This protocol aims at solving problems that hold back blockchain adoption, like energy waste. Its nominated Proof of stake model consumes much less energy than conventional proof of work blockchains, and Polkadot claims to have the lowest carbon footprint among proof of stake protocols.

Polkadot connects particular types of blockchain networks called parachains and parathreads. These networks are secured and integrated into Polkadot’s Relay Chain.

The programming language depends on the parachain or parathread that the smart contract will run.

That’s your chance to be ahead

Ask your developer friends if they’ve ever developed a smart contract. How many of them did? Probably not enough to make even a small squad.

Blockchain has been around for a little bit more than a decade, yet there are still not enough people out there to make use of its full potential. If you take the time to understand and experience what can be done with smart contracts, you’ll undoubtedly be ahead of something that will grow exponentially in the upcoming years.

You should research more profound into the existing blockchain platforms and do some experiments. Maybe learn solidity, write your first contract, and then deploy it to Ethereum’s network. This is going to open your mind to a whole new world.

Take this chance to be ahead in the change!

Do you think you have what it takes to be one of us?

At WAES, we are always looking for the best developers and data engineers to help Dutch companies succeed. If you are interested in becoming a part of our team and moving to The Netherlands, look at our open positions here.

WAES publication

Our content creators constantly create new articles about software development, lifestyle, and WAES. So make sure to follow us on Medium to learn more.

Also, make sure to follow us on our social media:
LinkedInInstagramTwitterYouTube

--

--