Smart contracts are a big part of what makes Ethereum tick.
In its core structure, Ethereum is similar to Bitcoin and many other blockchains. However, Ethereum is programmable, which means you can add smart contracts on top of its existing structure.
These smart contracts are self-executing programmes that are trained to perform specific actions in response to particular user behaviours. For example, they can tell a blockchain to:
- Transfer assets from one user to another.
- Create new assets.
- Approve transactions
- Distribute ownership of the blockchain’s tokens.
So, as you can see, they control a large part of the blockchain’s day-to-day operation. What’s more, they allow Ethereum to continue expanding: in other words, add new features and functions.
Ethereum is now a global hub of decentralised finance – a network of trustless, permissionless financial services based on blockchain technology. Smart contracts are crucial to these services.
In this edition of RhinoLearn we’re going to go under the hood and explain how smart contracts work in detail, so the next time you make a trade, swap or investment on Ethereum, you know how the magic’s happening.
Ok, so how do smart contracts actually work?
When we think of a traditional contract, we probably think of a piece of paper that’s used to represent an agreement, signed by all the individual parties.
But smart contracts are actually strings of code that perform specific functions on demand. And there is no need for anyone to ‘sign’ the contract: it executes automatically, without approval.
The reason it’s called a contract is that, like those old legal documents we’ve always relied on, it’s final and can’t be changed. Once you’ve programmed a smart contract, that’s it.
Each chunk of code is trained to execute, or run, when certain predetermined conditions are met. This is often referred to as an ‘if>then’ model: if a certain condition is met, then it will trigger the smart contract.
If you need a real-world example, think of a machine that’s attached to the door of a rental property. When the tenant comes home, they put their card into the machine. If they’ve paid their rent for the month, they’re allowed in. If not, then the machine will keep them locked out.
Smart contracts work in exactly the same way. They are programmed with specific ‘inputs’ and deliver ‘outputs’ when triggered.
These contracts can also be chained together to form workflows. One contract can trigger another when certain conditions are met, and so on. This creates a seamless user journey all along the blockchain.
What are the advantages of smart contracts?
Smart contracts are totally DeFi-friendly. They create a self-sustaining system which, once programmed, does not require a human to run it and offers total reliability to every single user.
Here are four specific advantages of using smart contracts:
- Security. Smart contracts are based on an underlying network which is extremely hard to hack. In fact, we’ve seen practically no smart contract hacks anywhere in the world (and, for context, there are over 1 million contracts on Ethereum alone). And if somebody wanted to change a single transaction related to a smart contract, they would have to change the entire network for that single record to be changed.
- Speed. Because smart contracts are programmed to execute automatically, they allow key interactions to happen in seconds, far quicker than if there was a human intermediary.
- Transparency. Smart contracts are typically made available for public view — in other words, every single member of the blockchain community can see the code. So everything is totally above board.
- Democracy. A smart contract doesn’t care whether you’re a multibillionaire crypto whale or a first-time trader: the rules are the same for everyone. So every single user enjoys the same privileges when using the blockchain.
Some might argue that smart contracts are a bit inflexible. That they won’t allow blockchains to bend and flex as their user base changes. But we think they’re a fantastic platform for the crypto age, and will continue to be so.
So, to summarise:
- Smart contracts are self-executing programmes that perform specific actions in response to particular user inputs.
- These programmes are final: they can’t be changed.
- Smart contracts are quick, secure, transparent and democratic.
- They are central to Ethereum and key to the wider future of blockchain technology.
If you’ve enjoyed this installment of RhinoLearn, check out our blog post on how Ethereum differs from Bitcoin. Tl:Dr – Ethereum rocks!