How do you read data outside the blockchain in a contract and how do Oracles work?
Smart blockchain contracts are limited to reading data only from the blockchain, i.e. those written in the block. How to provide data from outside the blockchain to the contract?
Oracles, is a well-known term for the mechanism by which a contract reads data from outside the blockchain. How does it work? This mechanism, or rather design pattern, DOES NOT have the ability to exceed the limitations of the blockchain. This means that oracles cannot read files, databases, or external services (APIs) directly. The oracle design pattern, however, makes it possible to “provide” external data to the blockchain. How?
External data to the smart contract (from outside the blockchain) can be provided only, as parameters (arguments) of its call. Oracles are software running outside the blockchain, which listens for “requests” by smart contracts for external data, and then provides this data to the smart contract, by calling the appropriate function of the contract, which will write this data to the blockchain. A smart contract, for example, has the ability to make a programmed off-chain (oracle) query for data from a certain API (e.g., BTC/PLN prices). The oracle software executes the query off the blockchain and then returns the result to the contract, calling its corresponding function with the result. In this way, the contract will “receive” data from outside, the execution will be automatic, but the mechanism itself is no different from manually calling the contract function, which writes the data to the blockchain, so that the contract can read it on its own.
Many myths have grown up around the topic of oracle, but the technical aspect of providing data to the blockchain itself is simple and does not cross the underlying technological barriers (e.g. Ethereum). It is worth knowing this when designing web3 solutions, as it has its limitations. Now that it’s known how to deliver data to the blockchain, it’s worth asking how to deliver data that is “correct”, true, and in a decentralized manner, consistent with the implementation of web3 solutions? This is a broad, difficult, but interesting topic. I will discuss it in future posts.