Last active
October 9, 2021 03:39
-
-
Save lukebyrne/203076b34a130073276aa4bf0c019d35 to your computer and use it in GitHub Desktop.
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
// Contract Deployed here: | |
// https://rinkeby.etherscan.io/address/0x401594dee6342a00ab522c44ad7c08eaf8517b1f | |
pragma solidity ^0.6.0; | |
import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol"; | |
contract APIConsumer is ChainlinkClient { | |
event RequestFulfilled( | |
bytes32 indexed requestId, | |
uint256 indexed volume | |
); | |
uint256 public volume; | |
address private oracle; | |
bytes32 private jobId; | |
uint256 private fee; | |
constructor() public { | |
setChainlinkToken(0x01BE23585060835E02B77ef475b0Cc51aA1e0709); | |
oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e; | |
jobId = "29fa9aa13bf1468788b7cc4a500a45b8"; | |
fee = 0.1 * 10 ** 18; // 0.1 LINK | |
} | |
function requestData() public returns (bytes32 requestId) { | |
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); | |
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD"); | |
request.add("path", "RAW.ETH.USD.VOLUME24HOUR"); | |
// Multiply the result by 1000000000000000000 to remove decimals | |
int timesAmount = 10**18; | |
request.addInt("times", timesAmount); | |
// Sends the request | |
return sendChainlinkRequestTo(oracle, request, fee); | |
} | |
/** | |
* Receive the response in the form of uint256 | |
*/ | |
function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId) { | |
emit RequestFulfilled(_requestId, _volume); | |
volume = _volume; | |
} | |
} |
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
// Contract Deployed here: | |
// https://rinkeby.etherscan.io/address/0xb306e2a5cc3adf26798a9adf567b9c0876c3566b | |
pragma solidity ^0.6.0; | |
import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol"; | |
contract APIConsumerTwo is ChainlinkClient { | |
event RequestFulfilled( | |
bytes32 indexed requestId, | |
bytes32 indexed volume | |
); | |
bytes32 public keyValue; | |
address private oracle; | |
bytes32 private jobId; | |
uint256 private fee; | |
constructor() public { | |
setChainlinkToken(0x01BE23585060835E02B77ef475b0Cc51aA1e0709); | |
oracle = 0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e; | |
jobId = "b0bde308282843d49a3a8d2dd2464af1"; | |
fee = 0.1 * 10 ** 18; // 0.1 LINK | |
} | |
function requestData() public returns (bytes32 requestId) { | |
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); | |
request.add("get", "https://8boczoauua5t.moralishost.com/mappings.json"); | |
request.add("path", "0|1|2"); | |
// Sends the request | |
return sendChainlinkRequestTo(oracle, request, fee); | |
} | |
/** | |
* Receive the response in the form of bytes32 | |
*/ | |
function fulfill(bytes32 _requestId, bytes32 _keyValue) public recordChainlinkFulfillment(_requestId) { | |
emit RequestFulfilled(_requestId, _keyValue); | |
keyValue = _keyValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment