Remix

使用 ChainLink 時出現編譯錯誤

  • March 30, 2021

我正在使用 Remix IDE 進行智能合約開發。我正在使用以下導入行

import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";

但是我在編譯時遇到了這個錯誤

DeclarationError: Undeclared identifier. setPublicChainlinkToken();

整個程式碼是:


pragma solidity ^0.6.0;

import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";

contract VersionControl {
   
   struct Asset {
       uint256 id;
       string name;
       string metadata;
       string ipfsHash;
       uint256 version;
       
       bool isPresent;
       
       mapping (address => uint256) contribution;
   }
   
   mapping (uint256 => Asset) assets;
               
   address tokenAddress;
   address owner;
   uint256 availabeId;
   
   address private oracle;
   bytes32 private jobId;
   uint256 private fee;
   
   constructor() public {
       owner = msg.sender;
       availabeId = 0;
       
       setPublicChainlinkToken();
       oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
       jobId = "29fa9aa13bf1468788b7cc4a500a45b8";
       fee = 0.1 * 10 ** 18; // 0.1 LINK
       
   }
   
   // function requestVolumeData() public returns (bytes32 requestId) 
   // {
   //     Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
       
   //     // Set the URL to perform the GET request on
   //     request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
       
   //     // Set the path to find the desired data in the API response, where the response format is:
   //     // {"RAW":
   //     //   {"ETH":
   //     //    {"USD":
   //     //     {
   //     //      "VOLUME24HOUR": xxx.xxx,
   //     //     }
   //     //    }
   //     //   }
   //     //  }
   //     request.add("path", "RAW.ETH.USD.VOLUME24HOUR");
       
   //     // Multiply the result by 1000000000000000000 to remove decimals
   //     int timesAmount = 10**18;
   //     request.addInt("times", timesAmount);
       
   //     // Sends the request
   //     return sendChainlinkRequestTo(oracle, request, fee);
   // }
   
   
}```

Ignore the requestVolumeData as it will be the place where I call the 3rd Party APIs

您必須將其繼承ChainlinkClient到您的契約中。

更改您的契約行:

contract VersionControl { 

contract VersionControl is ChainlinkClient {

引用自:https://ethereum.stackexchange.com/questions/95113