Skip to content

Instantly share code, notes, and snippets.

@ijonas
Last active October 17, 2022 04:32
Show Gist options
  • Save ijonas/f0df8b0eaef6bdb377c95ee7da84f01d to your computer and use it in GitHub Desktop.
Save ijonas/f0df8b0eaef6bdb377c95ee7da84f01d to your computer and use it in GitHub Desktop.
Antoine Oracle

Antoine's Oracle

This is a sample smart contract that connects to the Translucent Oracle on Goerli and retrieves a dynamic list of strings from a JSON API.

Oracle Job Details

  • Oracle Address - 0x188b71C9d27cDeE01B9b0dfF5C1aff62E8D6F434
  • Job ID - a72b502cccf444e49e4d4768017b6572
  • LINK token address on Goerli - 0x326C977E6efc84E512bB9C30f76E30c160eD06FB

Calling the API

The example.sol calls the Oracle with two required parameters

  • get - the URL of the API to retrieve.
  • path - a comma-separated JSON path to retrieve the list of wallets.

You could deploy this contract in Remix and call the following function:

requestBytes("https://gist.githubusercontent.com/ijonas/3b7234ac7417885c34c5744b89637e58/raw/8861d6a639e720497ed97ef88f79153e0836e495/example.json", "result,ids")

After about 15 seconds or so you would get a 3-value response that you can query on the example contract with

ids[0]
ids[1]
ids[2]

Files

  • example.json - a sample JSON response pretending to be the JSON API
  • example.sol - a working sample contract that can be deployed to Goerli and executed with the parameters described above.
{
"result": {
"ids": [
"1310",
"1792",
"1885"
]
}
}
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
/**
* @notice DO NOT USE THIS CODE IN PRODUCTION. This is an example contract.
*/
contract GetArray2 is ChainlinkClient {
using Chainlink for Chainlink.Request;
bytes[] public ids;
uint256 private constant ORACLE_PAYMENT = 0;
bytes32 constant jobId = "a72b502cccf444e49e4d4768017b6572";
constructor() {
// GOERLI
setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);
setChainlinkOracle(0x188b71C9d27cDeE01B9b0dfF5C1aff62E8D6F434);
}
/**
* @notice Request variable bytes from the oracle
*/
function requestBytes(string memory _url, string memory _path) public {
Chainlink.Request memory req = buildChainlinkRequest(
jobId,
address(this),
this.fulfillArray.selector
);
req.add("get", _url);
req.add("path", _path);
sendOperatorRequest(req, ORACLE_PAYMENT);
}
event RequestFulfilled(bytes32 indexed requestId, bytes[] indexed ids);
function fulfillArray(bytes32 requestId, bytes[] memory _ids)
public
recordChainlinkFulfillment(requestId)
{
emit RequestFulfilled(requestId, _ids);
ids = _ids;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment