Created
January 9, 2021 06:03
-
-
Save wrightkhlebisol/c554c035653ec91af4ac042f658eafe2 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
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: GPL-3.0 | |
pragma solidity ^0.6.0; | |
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/ChainlinkClient.sol"; | |
contract ChainlinkExample is ChainlinkClient { | |
uint256 public currentPrice; | |
address public owner; | |
address public ORACLE_ADDRESS = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e; | |
bytes32 constant JOBID = "29fa9aa13bf1468788b7cc4a500a45b8"; | |
uint256 constant private ORACLE_PAYMENT = 0.1 * 10 ** 18; | |
constructor() public { | |
setPublicChainlinkToken(); | |
owner = msg.sender; | |
} | |
function requestEthereumPrice() public onlyOwner{ | |
Chainlink.Request memory req = buildChainlinkRequest(JOBID, address(this), this.fulfill.selector); | |
req.add("get", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD"); | |
req.add("path", "USD"); | |
req.addInt("times", 100); | |
sendChainlinkRequestTo(ORACLE_ADDRESS, req, ORACLE_PAYMENT); | |
} | |
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId){ | |
currentPrice = _price; | |
} | |
modifier onlyOwner(){ | |
require(msg.sender == owner); | |
_; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment