# Ontology Oracle

More and more **dApps** now depend on outside world triggers. Here's a hypothetical scenario: A flight is scheduled to arrive at 10:00 AM. An **insurance smart contract** has been set in place which will be triggered if the flight is **delayed**, and all the beneficiaries of the insurance policy should receive 100 tokens as **compensation**.

A scenario such as this one involves many **variables**, and a **dApp** that implements a smart contract such as this will require a lot of outside world **data** such as flight information, insurance policy related data, relevant account information to actually carry out the transaction, etc.

**dApps** are becoming richer and are trying to encapsulate as much functionality as possible. As a result, more and more real world data needs to be processed, such as logistic information, stock prices, weather data, sports statistics and scores, etc.

Ontology Oracle is designed to deal with this issue of smart contracts not being able to interact with the outside world. It essentially plays the role of data transporter, making it possible for smart contracts to fetch outside world data.&#x20;

## Ontology Oracle Framework

![Oracle infrastructure](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LwWxLf-2R1aiZYBBsVb%2F-LwX2ZrujLyGpclx_ktP%2Foracle-framework.png?alt=media\&token=25d69bec-c6f3-4662-82d9-64b287e8ae87)

With reference to the illustration above, the infrastructure consists of two major parts-

1. **On-chain**
2. **Off-chain**

### Off-chain (Oracle Operator and Data Source)

The **Oracle node** and the **data source** are two parts of the Oracle network that exist off-chain. The nodes are linked to the **Ontology network** and listen for **requests** from the Oracle contracts. All nodes process the data requests **independently**. These nodes will support more blockchain networks in the future.

The operation carried out by the nodes consists of two important tasks:

* **Data crawling**
* **Data analysis**

The node fetches **data** from the **data sources** via external **APIs** and after processing and analyzing the **response** writes the **data** into the Oracle **contract** after **serializing** it into the format specified by the user.

### On-chain (Oracle Contract)

The Oracle contract primarily collects and stores the data sent by the node, making it available for other smart contracts to invoke and access.

### Oracle data and workflow

![Oracle network data flow](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LwWxLf-2R1aiZYBBsVb%2F-LwXfQjXPr9Vke7mlKeT%2FOracle%20Data%20flow.png?alt=media\&token=effe831f-e283-46e4-8f60-48e1478cfb24)

The data flow within the Oracle network, as illustrated above, can be described as follows:

1. The **client** issues **data requirements** using an **Oracle data request** to the Oracle contract
2. **Oracle contract** updates the received information in a **ledger** that functions like a **database**
3. An **Oracle node** picks up on this **request** and **fetches** this data using the **RPC** interface
4. The **node** fetches data from external data sources using **HTTP API**
5. The **node serializes** the received **data** based on the **client request** obtained earlier and **invokes** the **Oracle contract** to **transmit** the data
6. Other smart contracts on **client** side can then **invoke** this **Oracle contract** to **access** this data
