Skip to content

Instantly share code, notes, and snippets.

@mingderwang
Forked from cereum/AAPL.sol
Created September 18, 2020 07:43
Show Gist options
  • Save mingderwang/90cb074c4b5757bfd4ac458c5d3de3f4 to your computer and use it in GitHub Desktop.
Save mingderwang/90cb074c4b5757bfd4ac458c5d3de3f4 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.6+commit.6c089d02.js&optimize=false&gist=
/** 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.
* - Ropsten ETH faucet: https://faucet.ropsten.be/
* - Ropsten LINK faucet: https://ropsten.chain.link/
*/
pragma solidity ^0.6.0;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
address private oracle;
bytes32 private jobId;
uint256 private fee;
uint256 AAPLprice;
/**
* Network: Ropsten
* Oracle: Chainlink - 0xc99B3D447826532722E41bc36e644ba3479E4365
* Job ID: Chainlink - 3cff0a3524694ff8834bda9cf9c779a1
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0xc99B3D447826532722E41bc36e644ba3479E4365;
jobId = "3cff0a3524694ff8834bda9cf9c779a1";
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
/**
* Create a Chainlink request to retrieve API response, find the target price
* data, then multiply by 100 (to remove decimal places from price).
*/
function requestEthereumPrice() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
// Set the URL to perform the GET request on
request.add("get", "https://finnhub.io/api/v1/quote?symbol=AAPL");
request.add("path", "c");
// Multiply the result by 100 to remove decimals
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId)
{
AAPLprice = _price;
}
}
/** 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.
* - Ropsten ETH faucet: https://faucet.ropsten.be/
* - Ropsten LINK faucet: https://ropsten.chain.link/
*/
pragma solidity ^0.6.0;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
address private oracle;
bytes32 private jobId;
uint256 private fee;
uint256 AAPLprice;
/**
* Network: Ropsten
* Oracle: Chainlink - 0xc99B3D447826532722E41bc36e644ba3479E4365
* Job ID: Chainlink - 3cff0a3524694ff8834bda9cf9c779a1
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0xc99B3D447826532722E41bc36e644ba3479E4365;
jobId = "3cff0a3524694ff8834bda9cf9c779a1";
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
/**
* Create a Chainlink request to retrieve API response, find the target price
* data, then multiply by 100 (to remove decimal places from price).
*/
function requestEthereumPrice() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
// Set the URL to perform the GET request on
request.add("get", "https://finnhub.io/api/v1/quote?symbol=AAPL");
request.add("path", "c");
// Multiply the result by 100 to remove decimals
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId)
{
AAPLprice = _price;
}
}
/** 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.
* - Ropsten ETH faucet: https://faucet.ropsten.be/
* - Ropsten LINK faucet: https://ropsten.chain.link/
*/
pragma solidity ^0.6.0;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
address private oracle;
bytes32 private jobId;
uint256 private fee;
uint256 AAPLprice;
/**
* Network: Ropsten
* Oracle: Chainlink - 0xc99B3D447826532722E41bc36e644ba3479E4365
* Job ID: Chainlink - 3cff0a3524694ff8834bda9cf9c779a1
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0xc99B3D447826532722E41bc36e644ba3479E4365;
jobId = "3cff0a3524694ff8834bda9cf9c779a1";
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
/**
* Create a Chainlink request to retrieve API response, find the target price
* data, then multiply by 100 (to remove decimal places from price).
*/
function requestEthereumPrice() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
// Set the URL to perform the GET request on
request.add("get", "https://finnhub.io/api/v1/quote?symbol=AAPL");
request.add("path", "c");
// Multiply the result by 100 to remove decimals
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId)
{
AAPLprice = _price;
}
}
/** 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.
* - Ropsten ETH faucet: https://faucet.ropsten.be/
* - Ropsten LINK faucet: https://ropsten.chain.link/
*/
pragma solidity ^0.6.0;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
address private oracle;
bytes32 private jobId;
uint256 private fee;
uint256 AAPLprice;
/**
* Network: Ropsten
* Oracle: Chainlink - 0xc99B3D447826532722E41bc36e644ba3479E4365
* Job ID: Chainlink - 3cff0a3524694ff8834bda9cf9c779a1
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0xc99B3D447826532722E41bc36e644ba3479E4365;
jobId = "3cff0a3524694ff8834bda9cf9c779a1";
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
/**
* Create a Chainlink request to retrieve API response, find the target price
* data, then multiply by 100 (to remove decimal places from price).
*/
function requestEthereumPrice() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
// Set the URL to perform the GET request on
request.add("get", "https://finnhub.io/api/v1/quote?symbol=AAPL");
request.add("path", "c");
// Multiply the result by 100 to remove decimals
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId)
{
AAPLprice = _price;
}
}
/** 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.
* - Ropsten ETH faucet: https://faucet.ropsten.be/
* - Ropsten LINK faucet: https://ropsten.chain.link/
*/
pragma solidity ^0.6.0;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
address private oracle;
bytes32 private jobId;
uint256 private fee;
uint256 AAPLprice;
/**
* Network: Ropsten
* Oracle: Chainlink - 0xc99B3D447826532722E41bc36e644ba3479E4365
* Job ID: Chainlink - 3cff0a3524694ff8834bda9cf9c779a1
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0xc99B3D447826532722E41bc36e644ba3479E4365;
jobId = "3cff0a3524694ff8834bda9cf9c779a1";
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
/**
* Create a Chainlink request to retrieve API response, find the target price
* data, then multiply by 100 (to remove decimal places from price).
*/
function requestEthereumPrice() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
// Set the URL to perform the GET request on
request.add("get", "https://finnhub.io/api/v1/quote?symbol=AAPL");
request.add("path", "c");
// Multiply the result by 100 to remove decimals
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId)
{
AAPLprice = _price;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment