Skip to content

Instantly share code, notes, and snippets.

@alexroan
Last active September 11, 2021 15:18
Show Gist options
  • Save alexroan/969f87ab3091f65f8e21d16bcad8cab6 to your computer and use it in GitHub Desktop.
Save alexroan/969f87ab3091f65f8e21d16bcad8cab6 to your computer and use it in GitHub Desktop.
ExampleOracleClient.sol
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))
}
}
}
@christiantaggart
Copy link

christiantaggart commented Sep 11, 2021

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 to contracts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment