Chainlink Chinese

The Chainlink Chinese Developer Hub

Welcome to the Chainlink Chinese developer hub. You'll find comprehensive guides and documentation to help you start working with Chainlink Chinese as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

合约创建者

在外部适配器中使用参数

作为合约创建者,创建一个外部适配器和创建一个规范任务请求没什么不一样。您只需要知道适配器支持哪些参数。比如,我们的BraveNewCoin Chainlink 需要endpoint, coinmarket三个参数。请注意下面的方法通过run.add来为每个所需的值创建运行参数。

function requestMWAPrice(string _coin, string _market)
  public
  onlyOwner
  returns (bytes32 requestId) 
{
  ChainlinkLib.Run memory run = newRun(SPEC_ID, this, this.fulfill.selector);
  run.add("endpoint", "mwa-historic");
  run.add("coin", _coin);
  run.add("market", _market);
  run.add("copyPath", "data.-1.1");
  run.addInt("times", 100);
  requestId = chainlinkRequest(run, LINK(1));
}

在外部适配器中使用复制适配器

拷贝适配器与JSONParse适配器同样的功能,但是可以从外部适配器的回复中获取数据。

例如,一个适配器返回如下的JSON数据:

{
    "firstValue": "SomeValue",
    "details": {
        "close": "100",
        "open": "110",
        "current": "111"
    },
    "other": "GetData"
}

你想获取其中字段"open"的值,你可以指定路径,适配器会按照路径遍历JSON对象获得你想要的字段。

"copyPath": ["details", "open"]

在Solidity中,这个过程如下表示:

string[] memory path = new string[](2);
path[0] = "details";
path[1] = "open";
run.addStringArray("copyPath", path);

或者你也可以使用点来简化这一过程:

run.add("copyPath", "details.open");

Updated 9 months ago

合约创建者


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.