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';
/**
- Request testnet LINK and ETH here: https://faucets.chain.link/
- Find information on LINK Token Contracts and get the latest ETH and LINK faucets here: https://docs.chain.link/docs/link-token-contracts/ */
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"}