Last active
July 30, 2021 18:27
-
-
Save PatrickAlphaC/10ae2499f48f2932b38f34a96b124443 to your computer and use it in GitHub Desktop.
Deploy this in remix with https://remix.ethereum.org/#optimize=false&evmVersion=null&gist=10ae2499f48f2932b38f34a96b124443&runs=200&version=soljson-v0.8.6+commit.11564f7e.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; | |
/** | |
* @notice DO NOT USE THIS CODE IN PRODUCTION. This is an example contract. | |
*/ | |
contract GenericBigWord is ChainlinkClient { | |
using Chainlink for Chainlink.Request; | |
// variable bytes returned in a signle oracle response | |
bytes public data; | |
string public image_url; | |
/** | |
* @notice Initialize the link token and target oracle | |
* @dev The oracle address must be an Operator contract for multiword response | |
* | |
* | |
* Kovan Testnet details: | |
* Link Token: 0xa36085F69e2889c224210F603D836748e7dC0088 | |
* Oracle: 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8 (Chainlink DevRel Team) | |
* | |
*/ | |
constructor( | |
) { | |
setChainlinkToken(0xa36085F69e2889c224210F603D836748e7dC0088); | |
setChainlinkOracle(0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8); | |
} | |
////---- VARIABLE BYTES ARRAY RETURNED BY ORACLE ----//// | |
/** | |
* @notice Request variable bytes from the oracle | |
*/ | |
function requestBytes( | |
) | |
public | |
{ | |
bytes32 specId = "7a97ff8493ec406d90621b2531f9251a"; | |
uint256 payment = 100000000000000000; | |
Chainlink.Request memory req = buildChainlinkRequest(specId, address(this), this.fulfillBytes.selector); | |
req.add("get","https://ipfs.io/ipfs/QmZgsvrA1o1C8BGCrx6mHTqR1Ui1XqbCrtbMVrRLHtuPVD?filename=big-api-response.json"); | |
req.add("path", "image"); | |
requestOracleData(req, payment); | |
} | |
event RequestFulfilled( | |
bytes32 indexed requestId, | |
bytes indexed data | |
); | |
/** | |
* @notice Fulfillment function for variable bytes | |
* @dev This is called by the oracle. recordChainlinkFulfillment must be used. | |
*/ | |
function fulfillBytes( | |
bytes32 requestId, | |
bytes memory bytesData | |
) | |
public | |
recordChainlinkFulfillment(requestId) | |
{ | |
emit RequestFulfilled(requestId, bytesData); | |
data = bytesData; | |
image_url = string(data); | |
} | |
////---- END ----//// | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment