“The noblest pleasure is the joy of understanding.” – Leonardo da Vinci
When diving into the world of blockchain and cryptocurrencies, it’s easy to get drowned in the vast sea of tech jargon and complex names. If you’ve heard of Blockchain technology, you must have heard of smart contracts or oracle networks and how they’re changing the foundation of financial services. But have you ever wondered what exactly a smart contract is and how does it work? Let’s find out.
In our 2-part blog posts earlier, we understood the concept of blockchain technology, looked into its components, its significance, and its applications. Today, let’s take another step and get ourselves acquainted with the concepts of smart contracts and oracle networks.
What are Smart Contracts?
By definition, smart contracts are self-executing computer codes that are written on a distributed ledger. In simple language, smart contracts are similar to real-world contracts but stored digitally. The key point is – as they’re stored on a blockchain, smart contracts inherit two key properties – immutable and distributed. Meaning smart contracts, once deployed on a blockchain network, cannot be changed and distributed across the network, allowing anyone to interact with them.
Still confused? Well, let’s break it down further. So a blockchain is basically a ledger shared among all the peers containing all the transactions, i.e., a distributed ledger. Now rather than just writing a transaction detail such as “Alice transfers $10 to Bob” on a distributed ledger, what if you add a condition for the transfer to occur? Now let’s say Alice will transfer $10 to Bob only when it’s a full moon.
In this case, Alice will write a contract that will transfer the given amount to Bob upon checking the condition, i.e., if it’s a full moon or not. That, my friend, is a smart contract.
How Do They Work?
So, how do smart contracts work? Well, currently, Ethereum is the biggest smart contract platform so let’s talk about it.
Smart contracts are basically Ethereum accounts located on a specific address, just like your digital wallet has an address. The difference, however, is that a smart contract address is not controlled by a user but deployed on the network and runs as it is programmed. Users can interact with these smart contracts by submitting transactions to the given address.
For our earlier example, Alice will need to write a smart contract with predefined conditions along with Bob’s account details (Bob’s wallet address) and depositing the required amount in it. Once the smart contract is deployed, it will automatically transfer the funds to Bob’s account without any human intervention when its predefined conditions (occurrence of a full moon) are met.
Now, the question arises, if the predefined conditions for a smart contract rely on a real-world incidence, how do smart contracts pull that data? In our example, how would a smart contract know whether it’s a full moon or not?
One would say that’s simple – we can just pull the data through an API from a weather service. Well, unfortunately, we can’t do that for smart contracts. That’s because smart contracts are stored on a blockchain, making them immutable and irreversible. Therefore, relying on a single service can be dangerous as it can manipulate a smart contract. What if the given weather service feeds incorrect data to the smart contract?
That’s why we need decentralized oracle networks to avoid that single point of failure.
Oracle Networks (Decentralized)
Oracle networks, in essence, provide real-world data to a blockchain without a single point of failure. Basically, oracle networks act as a bridge for smart contracts to interact with real-world data.
So, in order to find out whether it’s a full moon or not, Alice’s smart contract can interact with an oracle network to pull the given data. Thus, avoiding the need for relying on a centralized entity such as a weather service.
So how do oracle networks ensure the correctness of data?
Well, oracle networks basically pull data from multiple sources to ensure the correctness of data. Simple as that. Oracle networks are a proof-of-stake blockchain network where every validator (or a data verifier) needs to stake a certain amount of cryptocurrency in order to participate in the network and earn rewards.
Thus incentivizing the validators to feed correct data and earn rewards whereas, at the same time, the stake acts as a safety deposit that can be slashed if the validator feeds incorrect data. And that’s how oracle networks provide data to smart contracts by utilizing multiple data inputs in a decentralized manner.