Skip to content

Instantly share code, notes, and snippets.

@jkongie
Created September 10, 2020 08:41
Show Gist options
  • Save jkongie/3add2f78a30cfd3b3aacd601a1d1755d to your computer and use it in GitHub Desktop.
Save jkongie/3add2f78a30cfd3b3aacd601a1d1755d to your computer and use it in GitHub Desktop.
Gets the symbol from the CoinGeckoAPI
/** 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.network/
* - Kovan LINK faucet: https://kovan.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 {
bytes32 public symbol;
address private oracle;
bytes32 private jobId;
uint256 private fee;
/**
* Network: Kovan
* Oracle: Chainlink - 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
* Job ID: Chainlink - 29fa9aa13bf1468788b7cc4a500a45b8
* Fee: 0.1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
jobId = "50fc4215f89443d185b061e5d7af9490";
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
/**
* Create a Chainlink request to retrieve API response, and find the ethereum symbol.
*/
function requestSymbol() 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://api.coingecko.com/api/v3/coins/ethereum?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false");
// Set the path to find the desired data in the API response, where the response format is:
// {"symbol":"eth"}
request.add("path", "symbol");
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, bytes32 _symbol) public recordChainlinkFulfillment(_requestId)
{
symbol = _symbol;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment