Skip to content

Instantly share code, notes, and snippets.

@PatrickAlphaC
Last active September 3, 2020 20:55
Show Gist options
  • Save PatrickAlphaC/f856530b20943e92ed6cc69c1285cdfe to your computer and use it in GitHub Desktop.
Save PatrickAlphaC/f856530b20943e92ed6cc69c1285cdfe to your computer and use it in GitHub Desktop.
/** This example code is designed to quickly deploy an example contract using Remix.
* If you have never used Remix, try our example walkthrough: https://docs.chain.link/docs/example-walkthrough
* You will need testnet ETH and LINK.
* - Kovan ETH faucet: https://faucet.kovan.be/
* - Kovan LINK faucet: https://kovan.chain.link/
*/
pragma solidity ^0.6.0;
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract TSLAStockDataKovan is ChainlinkClient {
address private oracle;
bytes32 private jobId;
uint256 private fee;
uint256 public tslaPrice;
constructor() public {
setPublicChainlinkToken();
oracle = 0x56dd6586DB0D08c6Ce7B2f2805af28616E082455; // oracle address
jobId = "802ec94e00184b789a016b8e71ae9fb4"; //job id
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
/**
* Make initial request
*/
function requestTSLAPrice() public {
Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfillEthereumPrice.selector);
req.add("function", "GLOBAL_QUOTE");
req.add("symbol", "TSLA");
string[] memory copyPath = new string[](2);
copyPath[0] = "Global Quote";
copyPath[1] = "05. price";
req.addStringArray("copyPath", copyPath);
req.addInt("times", 100000000);
sendChainlinkRequestTo(oracle, req, fee);
}
/**
* Callback function
*/
function fulfillEthereumPrice(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId) {
tslaPrice = _price;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment