The Graph Oracle (TGO) provides an oracle that allows users to exploit the power of the Graph directly from their smart contracts.
// Define query
string memory _queryString = "{cryptoKitties(where:{birthTime_gte:1514761200,birthTime_lt:1519858800},first:10) {owner}}";
// Define call back function that would be called when the query is completed
bytes4 _callback = bytes4(keccak256("updateKittyOwner(address[])"));
// Execute the query
oracle.createQuery(_queryHash, _company, _product, _queryString, false, _callback);Oracles are a third-party information source that allow smart contracts to process data coming from the real world directly on the blockchain. They are based on trusted agents, off-chain entities that provide the data.
The Graph is a powerful tool that allows users to query data from leading decentralized projects using an off-chain API.
TGO is the last piece of the puzzle, bridging the Graph queries and making them available directly to the blockchain.
We leverage the capabilities of Skale Sidechains to have lightning fast oraclized Graph queries. Furthermore, using the Skale decentralized file storage API we store the result of queries of any level of complexity, returning their storage ID to retrieve them.
We wrote and deployed the the TGO subgraph on ropsten, to get data on the oracle itself.
The backbone of TGO is theGraphOracle.sol smart contract, written in solidity. The off-chain agent is a python script logging to the oracle events, performing the off-chain API calls and submitting the results. The TGO subgraph is built in graphql.
TGO works as follows:
- A smart contract creates a query calling
createQueryand passing the query company, product and string as parameters theGraphOracleemits aQueryCreatedevent, which the off-chain agent intercepts- The off-chain agent performs the query on the Graph API and returns the result (in array form) to the original querying contract by calling a callback function
- If the query has the
_isStorageflag, the agent stores the result in a file using the Skale storage API
Query examples are provided by the TestCase.sol contract.
Ideally we would like to provide users with more flexibile queries, allowing them to get arbitrary JSON data instead of only arrays.
Address of Oracle and test contract in Ropsten
oracle addr: https://ropsten.etherscan.io/address/0x48e999889bc137bb4dcc2e28f9731ff9d5075084
testcase addr: https://ropsten.etherscan.io/address/0xa87825c3c77dce3292eee1a0ab71e40557bd99ac