Skip to content

Instantly share code, notes, and snippets.

@mingderwang
Forked from alexroan/APIConsumer.sol
Last active September 27, 2020 07:19
Show Gist options
  • Save mingderwang/7d5d8af26b083cafe1474fe7d6bc412b to your computer and use it in GitHub Desktop.
Save mingderwang/7d5d8af26b083cafe1474fe7d6bc412b 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=7d5d8af26b083cafe1474fe7d6bc412b
/** 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.6;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
uint256 public ethereumPrice;
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 = "29fa9aa13bf1468788b7cc4a500a45b8";
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://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD");
// Set the path to find the desired data in the API response, where the response format is:
// {"USD":243.33}
request.add("path", "USD");
// Multiply the result by 100 to remove decimals
request.addInt("times", 100);
// 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)
{
ethereumPrice = _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.
* - Kovan ETH faucet: https://faucet.kovan.network/
* - Kovan LINK faucet: https://kovan.chain.link/
*/
pragma solidity ^0.6.6;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract DIDConsumer is ChainlinkClient {
bytes32 public DIDdocument;
address private oracle;
bytes32 private jobId;
uint256 private fee;
/**
* Network: Kovan
* Oracle: Chainlink - 0xC5ebDFe933D65731AAce438D945F1817c02ffE8B
* Job ID: Chainlink - 8f5051fb3cdc4ae491b06c6bd6d90b79
* Fee: 1 LINK
*/
constructor() public {
setPublicChainlinkToken();
oracle = 0xC5ebDFe933D65731AAce438D945F1817c02ffE8B;
jobId = "8f5051fb3cdc4ae491b06c6bd6d90b79";
fee = 1 * 10 ** 18; // 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 requestDIDresolve() 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://dev.uniresolver.io/1.0/identifiers/did:elem:EiAS3mqC4OLMKOwcz3ItIL7XfWduPT7q3Fa4vHgiCfSG2A?fbclid=IwAR2L3u7EH9TAyKG0SflEPB115fQ6ujVfllI93wBJHwBuax_BykttaPf5B_k");
string[] memory path = new string[](1);
path[0] = "didDocument";
request.addStringArray("path", path);
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, bytes32 _result) public recordChainlinkFulfillment(_requestId)
{
DIDdocument = _result;
}
}
@mingderwang
Copy link
Author

@mingderwang
Copy link
Author

Reversion 19 works fine with ChainLink node .job

{
"initiators": [
{
"type": "runlog",
"params": {
"address": "0xc5ebdfe933d65731aace438d945f1817c02ffe8b"
}
}
],
"tasks": [
{
"type": "httpget",
"confirmations": 0,
"params": {
"get": "https://bitstamp.net/api/ticker/"
}
},
{
"type": "jsonparse",
"confirmations": null,
"params": {
"path": [
"last"
]
}
},
{
"type": "multiply",
"confirmations": null,
"params": {
"times": 100
}
},
{
"type": "ethuint256",
"confirmations": null,
"params": {
}
},
{
"type": "ethtx",
"confirmations": null,
"params": {
}
}
],
"startAt": "2020-02-09T15:13:03Z",
"endAt": null
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment