简体   繁体   English

Chainlink Large Responses 试图从任何 Api 返回一个字符串

[英]Chainlink Large Responses trying to return a String from any Api

I took the example code from the Chainlink docs ( https://docs.chain.link/docs/large-responses/ ) and modified it.我从 Chainlink 文档 ( https://docs.chain.link/docs/large-responses/ ) 中获取了示例代码并对其进行了修改。 Im trying to retrieve a string from an external API that is 60 bytes long.我正在尝试从 60 字节长的外部 API 检索字符串。 The unmodified example works fine.未经修改的示例工作正常。 I run the code on Kovan Tes.net.我在 Kovan Tes.net 上运行代码。

  using Chainlink for Chainlink.Request;

  // variable bytes returned in a signle oracle response
  bytes public data;
  string public image_url;

  constructor() {
    setChainlinkToken(0xa36085F69e2889c224210F603D836748e7dC0088);
    setChainlinkOracle(0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8);
  }

  function requestBytes(
  )
    public
  {
    bytes32 specId = "7a97ff8493ec406d90621b2531f9251a";
    uint256 payment = 100000000000000000;
    Chainlink.Request memory req = buildChainlinkRequest(specId, address(this), this.fulfillBytes.selector);
    req.add("get","--- ExampleApi---");
    req.add("path", "---ExamplePath---");
    requestOracleData(req, payment);
  }

  event RequestFulfilled(
    bytes32 indexed requestId,
    bytes indexed data
  );

  
  function fulfillBytes(
    bytes32 requestId,
    bytes memory bytesData
  )
    public
    recordChainlinkFulfillment(requestId)
  {
    emit RequestFulfilled(requestId, bytesData);
    data = bytesData;
    image_url = string(data);
  }

}

Thanks to Etherscan I know, that the Oracle receives a request, but doesnt send an answer.多亏了 Etherscan,我知道 Oracle 收到了一个请求,但没有发送答复。 Im not really sure why it doesnt work.我不太确定为什么它不起作用。 Maybe it has something to do with the jobId/specId.也许它与 jobId/specId 有关。

The large responses query at this time can't convert string -> bytes.此时的大响应查询无法转换字符串 -> 字节。

If you ran the node, you'd see the following error:如果您运行该节点,您会看到以下错误:

insertEthTx failed while constructing EthTx data: can't convert String (UEsn31KH7GPNtXCdqw6iJrw5VkhFIXjPS6a7jAal1BQSKRM) to bytes, bytes should be 0x-prefixed hex strings: invalid abi encoding

That's because "UEsn31KH7GPNtXCdqw6iJrw5VkhFIXjPS6a7jAal1BQSKRM" is a string an not a bytes object. You'd have to wrap this API in an API that converts the string -> a bytes object before returning it on-chain.那是因为“UEsn31KH7GPNtXCdqw6iJrw5VkhFIXjPS6a7jAal1BQSKRM”是一个字符串而不是一个字节 object。你必须将这个 API 包装在一个 API 中,在返回它之前转换字符串 -> 一个字节 8828288985402

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM