2

I'm having trouble understanding the flow:

Contract <==observes/injects== Oracle <==requestdata==> API

I read several articles like this and I'm aware of the theory of the flow. But what exactly is an oracle? Is it a smart contract? Is it an external service that watches for smart contract events and consequently makes something? Who pays for the oracle state changes (gas)? Can the oracle be seen as the client sade of an application?

3

An oracle is an external service (mostly outside blockchain) which inputs information to the blockchain upon request.

So the flow works like this:

1) Your contract sends a request to an oracle smart contract. For example to get the current temperature on Mars.

2) The oracle contract does something to catch the attention of the oracle service provider - probably emit an event but the exact means is not relevant.

3) The oracle's backend system notices that there is a new request for information in the oracle contract and it retrieves that information from somewhere

4) Oracle's backend system sends a transaction to the oracle contract with the requested information

5) The oracle contract receives the requested information in the transaction and it either forwards it directly to your contract or your contract has to pull the information from the oracle contract. Or perhaps the oracle's backend system can the transaction directly to your contract.

So oracle is just an external service which has a smart contract for communicating with users' smart contracts and relaying the data. Of course there are gas costs associated with the usage but that's up to the oracle provider to decide on who pays for them and how - it's a business decision. But in the end the end user pays for the service (gas).

| improve this answer | |
3

Smart contracts cannot "see" outside the Ethereum network. So for example, if you need a smart contract to know the weather it cannot just call a regular API over HTTP.

Instead, this weather information can be injected into another smart contract, either manually or by an automated process. The smart contract that holds this weather information is called an "oracle" but yes it is just a regular smart contract really. The information gets inside the oracle by a regular transaction that changes data on-chain.

Now that the weather information is inside the Ethereum network, other smart contracts can call the oracle (contract-to-contract calls are fine) and get weather information. If you have some automated off-chain process pushing the weather information into the oracle at regular intervals, then that could be said to be a component of the oracle too (and it could watch for on-chain events to trigger the process).

Who pays the gas? Well it is likely the oracle owner, whoever is pushing data into the smart contract normally has to pay the gas.

Whether its client or back-end depends I guess on your use-case. Personally, I normally think of it as back-end.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.