Smart Contracts

A smart contract is a blockchain program that can hold digital assets and will produce predictable results based upon input and qualifying conditions.

Smart contracts are computer programs built on top of blockchain networks that automatically execute when certain conditions are met. Smart contracts are the basis for decentralized marketplaces, ERC-20 tokens, NFTs, and more.

While exact implementation may vary, in general smart contracts are ‘deployed’ at specific blockchain addresses and are owned by the underlying blockchain network itself. They can hold and transfer digital assets, and will always follow through on their instructions according to conditions laid out at deployment.

Real World Analogy

In function, smart contracts are similar in many aspects to paper contracts. They can be used for a great variety of things that depend on the language of the contract.

As an example, paper contracts are commonly used as a binding agreement between parties to undertake agreed upon actions at agreed upon expenses. Take the following scenario:

Jack is an apple farmer. He has 50 apples. He wants to trade 25 of his apples for a quantity of oranges that approximately matches the same value, because oranges are more sought after in his part of the city. Unfortunately, Jack doesn’t know any orange farmers and wouldn’t trust any that he just met.

Jill is an orange farmer. She has 40 oranges. She wants to trade 20 of her oranges for a quantity of apples that approximately matches the same value, because apples are more sought after in her part of the city. Unfortunately, Jill doesn’t know any orange farmers and wouldn’t trust any that she just met.

Luckily, they both know a successful merchant in town named George. George is willing to connect the two and transport the apples and oranges between them in exchange for a fee of 2 oranges and 3 apples. The three come together and form a legally binding contract to make the arrangement official.

Situations like this happen in reality on a regular basis. Sometimes it ends well, other times it does not.

Ending 1

After many successful trades that made both Jack and Jill rich, George begins resenting the arrangement. One day he disappears, selling all of the harvest he was supposed to exchange to make a quick buck on the way out of the city.

Ending 2

After a few successful trades, George decides this isn’t the life he wants and ends the arrangement. Jack and Jill return to selling only their own harvest.

Each farmer is relying on George to act as a middleman in good faith. Even with a paper contract in play, the human element means that it is still predicated on trust - people evade and break the law every day, so George breaking a contract isn’t unbelievable.

In the world of blockchain networks, where digital asset tokens are traded rather than fruit, there's no need to find someone like George. Decentralized exchanges use smart contracts to automate the exchange. In this scenario, both Jack and Jill send the tokens to the underlying smart contract and it swaps the tokens and sends them back to the correct person.

On one side, Jack puts in his $ABC tokens for an amount of $DEF tokens worth a similar value.

On the other side, Jill puts in her $DEF tokens for an amount of $ABC tokens worth a similar value.

At no point during this exchange do they need to meet or know the party on the other end of their trade. So long as the underlying smart contract is secure, it's all done seamlessly and without directly interacting with another person.

Smart Contract Functionality And Dangers

Not all blockchain networks are capable of running smart contracts, and not all blockchain networks implement them in the same way. This section will largely speak about Smart Contract functionality on Ethereum, as it is the most active blockchain network capable of them.

The specific programming language and type of user that can deploy a smart contract depends on the blockchain network. Deploying a smart contract on Ethereum is a permissionless process - anyone that can write code and pay the underlying transaction fee can do it.

Individual smart contracts are static - once they exist on the blockchain network, they can’t be updated. Smart contracts are also composable - they can interact with each other by default. This is not a requirement, however. They can be fully functional as an individual piece of code or multiple smart contracts can be networked together to form complex programs.

Due to Ethereum’s permissionless design, anyone with internet access can write a smart contract to the blockchain. Once installed, it is visible to everyone and ready to follow through on its instructions.

Unfortunately, this means anyone can create a malicious contract to try to steal your digital assets. These scammers will often set up the malicious contract ahead of time, then wait for a moment of opportunity to try and trick people using a hacked twitter or discord account.

Since smart contracts are written by people, human error is another area that can result in loss of assets. A contract is only as good as its writer and its auditor, and even the smartest people can have dumb days.

Nearly any time an Ethereum wallet is asking your permission for something, it is due to interaction with a smart contract. It is important to practice good wallet hygiene when using blockchain networks.

Last updated