Reputation: 11
I took the example code from the Chainlink docs (https://docs.chain.link/docs/large-responses/) and modified it. Im trying to retrieve a string from an external API that is 60 bytes long. The unmodified example works fine. I run the code on Kovan Testnet.
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. Im not really sure why it doesnt work. Maybe it has something to do with the jobId/specId.
Upvotes: 1
Views: 139
Reputation: 6131
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.
Upvotes: 1