This is a code example from Solidity documentation:

pragma solidity ^0.4.11;

contract Oracle {
  struct Request {
    bytes data;
    function(bytes memory) external callback;
  Request[] requests;
  event NewRequest(uint);
  function query(bytes data, function(bytes memory) external callback) {
    requests.push(Request(data, callback));
    NewRequest(requests.length - 1);
  function reply(uint requestID, bytes response) {
    // Here goes the check that the reply comes from a trusted source

contract OracleUser {
  Oracle constant oracle = Oracle(0x1234567); // known contract
  function buySomething() {
    oracle.query("USD", this.oracleResponse);
  function oracleResponse(bytes response) {
    require(msg.sender == address(oracle));
    // Use the data

Is this the right flow?

  1. A contract (the requestor) instantiates the Oracle

  2. It queries the Oracle providing some data (query parameters) along with a callback function

  3. Oracle stores the request in an array

  4. Oracle triggers an event passing the index where the request is stored

  5. An external server listens the event from an RPC and invokes the "reply" method from the Oracle contract, passing the requestID and the actual response from an external source

  6. Oracle "reply" method verifies if external caller is trustworthy (with public key encryption or any other crypto solution) then executes the callback provided by requestor contract

  7. The requestor contract gets data from the outer world.

Is something missing?

Your Answer

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

Browse other questions tagged or ask your own question.