Created
September 12, 2020 08:08
-
-
Save viraj124/b38a41e3d2adccc71d5183b8d456f82e to your computer and use it in GitHub Desktop.
This file contains 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
pragma solidity 0.6.0; | |
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol"; | |
contract Adapter is ChainlinkClient { | |
uint256 public ethereumPrice; | |
address private oracle; | |
bytes32 private jobId; | |
uint256 private fee; | |
/** | |
* Network: Kovan | |
* Oracle: Chainlink - 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e | |
* Job ID: Chainlink - 29fa9aa13bf1468788b7cc4a500a45b8 | |
* Fee: 0.1 LINK | |
*/ | |
constructor() public { | |
setPublicChainlinkToken(); | |
oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e; | |
jobId = "29fa9aa13bf1468788b7cc4a500a45b8"; | |
fee = 0.1 * 10 ** 18; // 0.1 LINK | |
} | |
/** | |
* Create a Chainlink request to retrieve API response, find the target price | |
* data, then multiply by 100 (to remove decimal places from price). | |
*/ | |
function requestEthereumPrice() public returns (bytes32 requestId) | |
{ | |
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); | |
// Set the URL to perform the GET request on | |
request.add("get", "https://api.opensea.io/api/v1/asset/0xf5b0a3efb8e8e4c201e2a935f110eaaf3ffecb8d/98819/"); | |
// // Set the path to find the desired data in the API response, where the response format is: | |
// // {"USD":243.33} | |
request.add("path", "last_sale.payment_token.usd_price"); | |
// // Multiply the result by 100 to remove decimals | |
// request.addInt("times", 100); | |
// Sends the request | |
return sendChainlinkRequestTo(oracle, request, fee); | |
} | |
/** | |
* Receive the response in the form of uint256 | |
*/ | |
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId) | |
{ | |
ethereumPrice = _price; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment