Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
techflare prod smart contract example
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.7;
import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";
contract TechFlareConsumerProd is ChainlinkClient {
uint256 public value;
address private oracle;
bytes32 private jobId;
uint256 private fee;
/**
* Network: Mainnet
* Oracle:
* Name: TechFlare Mainnet
* Listing URL: https://market.link/nodes/0c4cdcd0-f09b-4b63-a8ac-17ba06c3f838/metrics?network=1
* Address: 0xb25FCb293571ba083bc33dA71159ed2a39A051A1
* Job:
* Name: TechFlare API
* Listing URL: https://market.link/jobs/48eaf76d-fd2b-43b0-aae3-91087902c760?network=1
* ID: 4144bfcb058245ecbbd746044d49762f
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0xb25FCb293571ba083bc33dA71159ed2a39A051A1;
jobId = "4144bfcb058245ecbbd746044d49762f";
fee = 0.1 * 10 ** 18; // 0.1 LINK (Varies by network and job)
}
/**
* Create a Chainlink request to retrieve API response, find the target
* data, then multiply by 1000000000000000000 (to remove decimal places from data).
************************************************************************************
* STOP! *
* THIS FUNCTION WILL FAIL IF THIS CONTRACT DOES NOT OWN LINK *
* ---------------------------------------------------------- *
* Learn how to obtain testnet LINK and fund this contract: *
* ------- https://docs.chain.link/docs/acquire-link -------- *
* ---- https://docs.chain.link/docs/fund-your-contract ----- *
* *
************************************************************************************/
function requestAPIData() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
request.add("n", "btc"); // add query parameter n(name) in data json
request.add("p", "m"); // add query parameter p(period) in data json
string[] memory path = new string[](2);
path[0] = "sma";
path[1] = "5";
request.addStringArray("copyPath", path);
// Multiply the result by 1000000000000000000 to remove decimals
int timesAmount = 10**18;
request.addInt("times", timesAmount);
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, uint256 _value) public recordChainlinkFulfillment(_requestId)
{
value = _value;
}
// function withdrawLink() external {} - Implement a withdraw function to avoid locking your LINK in the contract
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment