0

chainlink I've altered the chainlink large Response example to read a JSON file that contains multiple data that I wish to bring into and store in the smart contract

//SPDX-License-Identifier: MIT pragma solidity ^0.8.7;

import '@chainlink/contracts/src/v0.8/ChainlinkClient.sol'; import '@chainlink/contracts/src/v0.8/ConfirmedOwner.sol';

/**

contract GenericLargeResponse is ChainlinkClient, ConfirmedOwner { using Chainlink for Chainlink.Request;

// variable bytes(arbitrary-length raw byte data) returned in a single oracle response bytes public data; bytes public imgdata; string public image; string public name; bytes32 private jobId; uint256 private fee; /** * @notice Initialize the link token and target oracle * @dev The oracle address must be an Operator contract for multiword response * * * Rinkeby Testnet details: * Link Token: 0x01BE23585060835E02B77ef475b0Cc51aA1e0709 * Oracle: 0xf3FBB7f3391F62C8fe53f89B41dFC8159EE9653f (Chainlink DevRel) * jobId: 7da2702f37fd48e5b1b9a5715e3509b6 * */ constructor() ConfirmedOwner(msg.sender) { setChainlinkToken(0x01BE23585060835E02B77ef475b0Cc51aA1e0709); setChainlinkOracle(0xf3FBB7f3391F62C8fe53f89B41dFC8159EE9653f); jobId = '7da2702f37fd48e5b1b9a5715e3509b6'; fee = (1 * LINK_DIVISIBILITY) / 10; // 0,1 * 10**18 (Varies by network and job) } /** * @notice Request variable bytes from the oracle */ function requestBytes() public { Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfillBytes.selector); req.add( 'get', 'https://ipfs.io/ipfs/QmWBxuuuqDxjiSvHsf52bQVkQ7Sqv1dLx4DJPFZ4KdsHGZ/1.json' ); req.add('path', 'name'); req.add('path', 'image'); sendChainlinkRequest(req, fee); } event RequestFulfilled(bytes32 indexed requestId, bytes indexed data, bytes indexed imgdata); /** * @notice Fulfillment function for variable bytes * @dev This is called by the oracle. recordChainlinkFulfillment must be used. */ function fulfillBytes(bytes32 requestId, bytes memory bytesData, bytes memory imgdata_) public recordChainlinkFulfillment(requestId) { emit RequestFulfilled(requestId, bytesData, imgdata_); data = bytesData; name = string(data); imgdata = imgdata_; image = string(imgdata); } /** * Allow withdraw of Link tokens from the contract */ function withdrawLink() public onlyOwner { LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress()); require(link.transfer(msg.sender, link.balanceOf(address(this))), 'Unable to transfer'); } 

}

This is the data its trying to read: {"name":"Token #1","description":"Ful player NFT #1","image":"ipfs//QmetFE2HRTFMkz5WamY8aw2hCDf7BJjXQPWv3et1bVqtER/1.jpg"}

1 Answer 1

1

In general your approach in your contract is adequate, but I would make the small change to match a job-spec a node operator would need to add to their node to service your requests.

req.add('path1', 'name'); req.add('path2', 'image'); 

In general, if you have two different paths, but have them assigned to the same variable, the request will error out.

Finally, your request type (get > x2 bytes) is a non-standard job request. You would have to find a node operator to host the associated job-spec on their node/oracle for your smart contract to work as intended.

If you want I can host this job on our node if you like, you can message me on our discord server: https://discord.gg/PgxRVrDUm7

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.