Last active
April 10, 2021 08:00
-
-
Save mingderwang/25c68b3d9c4d7b6faec82eab7bc46f7b 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=25c68b3d9c4d7b6faec82eab7bc46f7b
This file contains 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.network/ | |
* - Kovan LINK faucet: https://kovan.chain.link/ | |
*/ | |
// deploy this to address: 0xB90556f06d1347aEa4E41d78BA36fEEb2DD98A0C | |
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 | |
* Sample request Contract: 0x9b767eb863AFd6cC1A80040D4050103f49B337c1 | |
* Fee: 1 LINK | |
*/ | |
constructor() public { | |
setPublicChainlinkToken(); | |
oracle = 0x53912D3EE483Ac1549E1d47f154867aDf06DBa42; | |
jobId = "91a1ad73762844df8cf959fc2fb07bdf"; | |
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(string memory _DID_id) public returns (bytes32 requestId) | |
{ | |
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); | |
// Set the URL to perform the GET request on | |
// sample DID_id: "did:sov:WRfXPg8dantKVubE3HX8pw" (good) or "did:bid:6cc796b8d6e2fbebc9b3cf9e" (bad) | |
request.add("get", append("https://dev.uniresolver.io/1.0/identifiers/", _DID_id)); | |
string[] memory path = new string[](2); | |
path[0] = "didDocument"; | |
path[1] = "id"; | |
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; | |
} | |
function append(string memory a, string memory b) internal pure returns (string memory) { | |
return string(abi.encodePacked(a, b)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://link.muzamint.com:6688/jobs/91a1ad73762844df8cf959fc2fb07bdf