Last active
September 3, 2020 20:55
-
-
Save PatrickAlphaC/f856530b20943e92ed6cc69c1285cdfe to your computer and use it in GitHub Desktop.
Deploy to remix using: https://remix.ethereum.org/#version=soljson-v0.6.6+commit.6c089d02.js&optimize=false&gist=f856530b20943e92ed6cc69c1285cdfe&evmVersion=null - Alpha Vantage External Adpater on Kovan using the Linkpool node
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
/** 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