NODE OPERATORS Overview Running a Chainlink Node Fulfilling Requests Run an Ethereum Client Performing System Maintenance Connecting to a Remote Database Configuration Variables Enabling HTTPS Connections Best Security and Operating Practices Best Practices for Nodes on AWS Miscellaneous
ORACLE JOBS Migrating to v2 Jobs Jobs Cron Direct Request Flux Monitor Keeper Off-chain Reporting Webhook Tasks HTTP Bridge JSON Parse CBOR Parse ETH ABI Decode ETH ABI Decode Log ETH ABI Encode ETH Call ETH Tx Multiply Divide Any Mean Median Mode Sum
External Adapters in Solidity
Tell us more about your experience.
Using parameters with an External Adapter
As a contract creator, using an external adapter is no different than creating a request for any other job spec. You will simply need to know which parameters are supported by the adapter. Notice the method below uses req.add
to create a run parameter for each required value.
function requestMWAPrice(string _coin, string _market)
public
onlyOwner
returns (bytes32 requestId)
{
Chainlink.Request memory req = buildChainlinkRequest(SPEC_ID, this, this.fulfill.selector);
req.add("endpoint", "mwa-historic");
req.add("coin", _coin);
req.add("market", _market);
req.add("copyPath", "data.-1.1");
req.addInt("times", 100);
requestId = sendChainlinkRequest(req, oraclePayment);
}
JavaScript
Using the Copy adapter with an External Adapter
The Copy adapter allows for the same functionality of the JsonParse adapter but for getting data from the external adapter's response.
For example, if an adapter returns JSON data like what is below:
{
"firstValue": "SomeValue",
"details": {
"close": "100",
"open": "110",
"current": "111"
},
"other": "GetData"
}
JSON
And you wanted the value in the field "open", you would specify the path for the adapter to walk through the JSON object to your desired field.
"copyPath": ["details", "open"]
JSON
In Solidity, this would look like:
string[] memory path = new string[](2);
path[0] = "details";
path[1] = "open";
run.addStringArray("copyPath", path);
JavaScript
Or you can use dot-notation JSONPath to simplify it:
run.add("copyPath", "details.open");
JavaScript