Skip to content

Instantly share code, notes, and snippets.

@PatrickAlphaC
Last active July 30, 2021 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickAlphaC/dcf554e03223427aa4c7aef099d98429 to your computer and use it in GitHub Desktop.
Save PatrickAlphaC/dcf554e03223427aa4c7aef099d98429 to your computer and use it in GitHub Desktop.
//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.
*
* The job spec for this node is located here:
* https://gist.github.com/PatrickAlphaC/53848768b3ca6c747cf1166ccb2f65ec
*
* It is meant SOLEY for the KOVAN testnet
*
*/
contract MultiWord is ChainlinkClient {
using Chainlink for Chainlink.Request;
// multiple params returned in a single oracle response
uint256 public usd;
uint256 public eur;
uint256 public jpy;
/**
* @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);
}
////---- MULTIPLE PARAMETERS REQUESTED & RETURNED BY ORACLE ----////
/**
* @notice Request mutiple parameters from the oracle in a single transaction
*
* Kovan Testnet Details:
* specId: 645661528ea44aa7b137ed9f9d54c3d5
* payment: 100000000000000000 (0.1 LINK)
*
* This job makes a request to:
* https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,JPY,EUR
* Which responds with:
* ```
* {
* "USD": 40030.71,
* "JPY": 4384352.56,
* "EUR": 33792.04
* }
*
* ```
* The job automatically grabs the USD, JPY, and EUR responses
*/
function requestMultipleParameters()
public
{
bytes32 specId = "645661528ea44aa7b137ed9f9d54c3d5";
uint256 payment = 100000000000000000;
Chainlink.Request memory req = buildChainlinkRequest(specId, address(this), this.fulfillMultipleParameters.selector);
req.addUint("times", 10000);
requestOracleData(req, payment);
}
event RequestMultipleFulfilled(
bytes32 indexed requestId,
uint256 indexed usd,
uint256 indexed eur,
uint256 jpy
);
/**
* @notice Fulfillment function for multiple parameters in a single request
* @dev This is called by the oracle. recordChainlinkFulfillment must be used.
*/
function fulfillMultipleParameters(
bytes32 requestId,
uint256 usdResponse,
uint256 eurResponse,
uint256 jpyResponse
)
public
recordChainlinkFulfillment(requestId)
{
emit RequestMultipleFulfilled(requestId, usdResponse, eurResponse, jpyResponse);
usd = usdResponse;
eur = eurResponse;
jpy = jpyResponse;
}
////---- END ----////
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment