Last active
September 11, 2021 15:18
-
-
Save alexroan/969f87ab3091f65f8e21d16bcad8cab6 to your computer and use it in GitHub Desktop.
ExampleOracleClient.sol
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
pragma solidity 0.6.0; | |
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol"; | |
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/vendor/Ownable.sol"; | |
contract ExampleOracleClient is ChainlinkClient, Ownable { | |
address constant private ORACLE = 0x83dA1beEb89Ffaf56d0B7C50aFB0A66Fb4DF8cB1; | |
string constant private JOB_ID = "93547cb3c6784ec08a366be6211caa24"; | |
uint256 constant private ORACLE_PAYMENT = 1 * LINK / 10; | |
uint256 public currentPrice; | |
event RequestEthereumPriceFulfilled( | |
bytes32 indexed requestId, | |
uint256 indexed price | |
); | |
constructor() public Ownable() { | |
setPublicChainlinkToken(); | |
} | |
function requestEthereumPrice() public onlyOwner { | |
Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(JOB_ID), address(this), this.fulfillEthereumPrice.selector); | |
sendChainlinkRequestTo(ORACLE, req, ORACLE_PAYMENT); | |
} | |
function fulfillEthereumPrice(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId) { | |
emit RequestEthereumPriceFulfilled(_requestId, _price); | |
currentPrice = _price; | |
} | |
function withdrawLink() public onlyOwner { | |
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress()); | |
require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer"); | |
} | |
function stringToBytes32(string memory source) private pure returns (bytes32 result) { | |
bytes memory tempEmptyStringTest = bytes(source); | |
if (tempEmptyStringTest.length == 0) { | |
return 0x0; | |
} | |
assembly { // solhint-disable-line no-inline-assembly | |
result := mload(add(source, 32)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/vendor/Ownable.sol";
Needs to be changed to :
import "https://github.com/smartcontractkit/chainlink/contracts/src/v0.6/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/contracts/src/v0.6/vendor/Ownable.sol";
The path
evm-contracts
was changed tocontracts