1

anyone know how oraclize api is working. I read the source code files on github.com/oraclize/ethereum_api . it need a "__callback" function in my contract to receive the result, is it means there has a off-chain application on watching events, and provide the result?

1

Oraclize uses a backend program to listen for the queries and provides results from different types of data sources, including IPFS, random.org, and others.

They are able to provide proof that the data returned has not been manipulated. In the case of random.org, they provide the signature of the results, the final user can then recover the public key of random.org using that signature.

The pricing is a few cents per query and the subject should assume the gas cost of the transaction. Unfortunately, they do not have a way to determine the gas beforehand and the user should provide sufficient amount of ether to cover the gas cost. If not, the query won't be executed. Furthermore, they do not return the unused gas, which is pretty bad if your application requires continuous use of the service.

The results are passed to a function that should match the expected name, this is because the interface to the contract should be known beforehand, so oraclize can call it. The user can then put the code that it wants to be executed inside the callBack function.

I hope this helps,

UPDATE

Someone commented that is false that oraclize doesn't return the unspent gas and claim that it will remove the downvote if I remove that claim.

Thing is that Oraclize state that they do not return the unspent gas in their documentation:

Smart contract developers should estimate correctly and minimize the cost of their __callback method, as any unspent gas will be returned to Oraclize and no refund is available.

The commenter is wrong. However, it adds a piece of information that is valuable as he/she indicates that there are other payment methods that oraclize accepts, like off-chain payments in fiat in which the gas charged is what is spent plus the fee.

  • 1
    As a note, I downvoted due to some incorrect points. Namely the fact about not returning unused gas, Oraclize offers off-chain payments to high-volume clients to pre-pay for queries in fiat and only get charged for the amount of gas used + oraclize fees. Regarding calculating gas before hand, Oraclize cannot predict what the result will be, the developer is expected to know the possible gas ceiling their logic will use, and set that as the gas limit for the callback. Oraclize does provide a method to see how much a query will cost, so one can know exactly the amount of ETH to send. – DenisM May 29 '18 at 21:59
  • If you edit your answer by either removing the points that appear incorrect to me or correct them, I will remove/change to an upvote. Also, I think you meant Oraclize uses a backend program, and not frontend. – DenisM May 29 '18 at 22:01
  • What I wrote in the answer is true and you can verify this in Oraclize documentation, which I added to the answer as an Update to prove that you are wrong and probably biased because seems like you are related to Oraclize in some way. I did change the word frontend by backend, in that you were right. Here you have what Oraclize says in his documentation: "Smart contract developers should estimate correctly and minimize the cost of their __callback method, as any unspent gas will be returned to Oraclize and no refund is available." – Jaime May 30 '18 at 7:55
  • For full disclosure, I am contracted by Oraclize, but of course attempt not to be biased. Unfortunately documentation doesn't necessarily always cover everything. I downvoted because parts appeared incorrect to me, and of course wanted to be fair and comment on what appeared incorrect to me, no malice intended. I think your updated edit covers the points I went over, and maybe I misunderstand the point about gas estimation. I will change to an upvote. The documentation is a WIP so you are not to blame for omission on the refund point, I'll note about adding the off-chain alternative. – DenisM May 30 '18 at 18:10
3

It's a bit tough to explain completely.

But there's an oraclize contract on the main net and testnets (Kovan, Rinkeby, Ropsten..) which you can import and use it's functions.

Then after your queries are done, a 3rd party (Oraclize.it) provides you the results. They also give result data encryption possibilities and some kind of proofs that allow them to demonstrate to you that the info you asked for is real and untouched/Unread.

The __callback function allows them to send you back the data and then, you can override the function in order to do something with it.

On it's API there's plenty of examples that will allow you to understand how it works.

Hope it helps.

1

The Oraclize architecture on Ethereum is separated into a few parts. The core parts are made up of the on-chain smart contracts, a set of contracts deployed on the ethereum network and one you need to inherit into your own to properly connect with them, and a proprietary Oraclize engine which handles all the off-chain operations. In the case of proofs being requested, you can add the proof provider to the architecture, which in the case of TLSNotary is a locked-down AWS instance acting as the auditor, Android Proof is an Android smartphone with TEE, or in case of Random is a Ledger Nano S running a custom app.

Regarding the on-chain portion, the contract you inherit is called the oraclizeAPI. The two your contract will be reaching out to is the OraclizeAddressResolver (OAR) which serves the function of pointing to the OraclizeConnector contract, where the on-chain logic for the service lives. These mechanism allows the OraclizeConnector to be extensible and upgraded, although an important tenet for Oraclize is to ensure backwards compatibility, and we've had a few updates that have been seamless so far. The aforementioned contracts may be explored here: https://github.com/oraclize/ethereum-api/tree/master/connectors and are verified on etherscan.

The engine watches the aforementioned deployed contracts, for specific logs, and when it sees them, it executes them as requested, and then sends the results on-chain alongside some authenticity proof if requested. This engine is general purpose and not ethereum-specific, it has support for other blockchains and mechanisms of query/answer/proofs transmission.

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.