How to create an oracle for your own blockchain?

What is a blockchain oracle?

An oracle is a third-party source of information that you (have to) trust. The oracle can submit information to your blockchain. This information can then be used to execute a business logic, based on predefined conditions, programmed in your smart contract. 

What types of oracles are there?

There are at least 5 different types of oracles, all with different functions or characteristics, which can be created for your own blockchain. With any oracle pushing data, you can let a cron smart contract self-execute on one (or more blockchains with Interchain), based on pre-defined code. The frequency can be set on any cadence from every minute, only on certain days of the week or month, and everything in between.

Software oracles or deterministic oracles.  

This type of oracle is the most well known and most used. It is a single source data feed that can integrate with a smart contract to create transactions based on predefined rules. If you decide that you trust the data coming from an oracle you intend to use, then you can go for the deterministic oracle, providing data quickly from the outside world to the digital world, executing predefined code in your smart contract. 

Hardware Oracles 

Hardware oracles can be RFID tags and sensors inside cars or products, or any other type of hardware sending information from the physical world to the digital world. Take for example Knowledge Perk, using Dragonchain’s technology to put roast data points on the blockchain. The application was built and used inside the store within 4 days. The roast data points are obtained through IoT devices inside the coffee roaster, then stored on the blockchain. This allows customers to see the entire roasting process. It’s a way for Knowledge Perk to use blockchain technology to differentiate their services from other coffee chains like Starbucks and Woods coffee. By scanning the QR code on the packaging, anyone buying coffee at Knowledge Perk can see all of this decentralized and immutable data. Whether you make wine, own a beer brewery, grow flowers and plants, or are responsible for water management in your local town or state. With (hardware) oracles you can quickly get all of that data on chain. In a matter of minutes with our blockchain platform, as you can see in the oracle demo further down this article. 

Inbound oracles

Inbound oracles supply external data to a smart contract. A news website providing us with the latest weather forecasts and current temperature is an inbound oracle. We could also find examples in games such as Pokemon Go. Based on our GPS activity, the game determines whether we walked enough distance to hatch our eggs. Pokemon Go added some restrictions to prevent gaming the system, such as the maximum speed that we are allowed to walk. If we walk too fast, or use a scooter or a car, the distance we’ve traveled will not be added to the required distance to hatch an egg. For this, the Pokemon Go team must rely on external sources such as GPS. They must trust the data points and find more secure and non-tamperable ways to monitor our activity.

Outbound Oracles 

Outbound oracles communicate data from smart contracts to an external network or blockchain. The smart contract itself can act as an outbound oracle. As an example we can use Dragonchain’s Wyrm Holes to show a combination of both outbound and inbound oracles used in an innovative solution for cross-chain token transfers. In the following use case, native Ethereum (ERC20) tokens are sent from the Ethereum blockchain (ETH) into a Wyrm Hole and sent out as foreign tokens to the NEO blockchain. 

A user sends tokens to the Wyrm Hole address on Ethereum. The ETH watcher sends the transaction to the Wyrm Hole contract. The Wyrm Hole contract validates the transaction and credits the user account. The user selects the NEO blockchain to send tokens to. The Wyrm Hole contract validates and publishes the transaction to the NEO blockchain, minting tokens. The NEO publisher invokes the Wyrm Hole contract; confirming the transaction is complete then debiting the user account.

Consensus-based Oracles

In contrast to software oracles, consensus-based oracles do not use a single source. There are several ways to create and use decentralized oracles. One would be a rating system inside a prediction market. To reduce risk and provide more security, a combination of oracles might be used. For example you could take the average of 5 oracles. Or, 5 out of 7 oracles can determine the outcome of an event. Consensus-based oracles are slower, only because it takes more time to reach consensus. If we can not trust an oracle that gives us the  information we need, or if we are not certain of the accuracy at all times, a slightly safer path may be through consensus-based oracles. Especially if there exists a large sum of money or legal ramifications behind it.

Why oracles require trust. 

The biggest and possibly only disadvantage regarding use of an oracle is the requirement we trust them and their maintainers. The Oracle Problem is defined as the security, authenticity, and trust conflict between third-party oracles and their trustless execution of smart contracts. The digital world needs to communicate with the physical world. Dragonchain might be the preferred blockchain platform to connect the outside world with blockchain, in a way that smart contracts may utilize data residing in legacy systems.

The conflict between third-party oracles and the execution of smart contracts is not a serious problem for every blockchain application. It only requires specific workarounds and precautionary measures for certain use cases, depending on the instance. Consensus-based oracles reduce risk, but one solution does not fit all issues. Is it even possible to completely remove the issue of trust with oracles, similar to Satoshi solving the double spend problem? In our Telegram community, a member asked this question: