Solidity - 简单 API 请求 - 未声明的标识符问题
Solidity - Simple API request - Undeclared identifier problem
我是 Solidity 的新手,目前,我正在尝试部署一个简单的智能合约,请求 ETH 价格 “LOWDAY” 和“HIGHDAY”。我已经做了一个非常相似的 SC,它只请求“VOLUME24HOUR”,而且效果很好。这是我得到的错误:
contracts/API_Consumer_Info.sol:24:66: DeclarationError: Undeclared
identifier. Did you mean "jobID"? Chainlink.Request memory request =
buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
^---^
pragma solidity ^0.6.7;
import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumerInfo is ChainlinkClient
{
uint256 public lowDay;
uint256 public highDay;
address private oracle;
bytes32 private jobID;
uint256 private fee;
constructor() public
{
setPublicChainlinkToken();
oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
jobID = "29fa9aa13bf1468788b7cc4a500a45b8";
fee = 0.1 * 10 ** 18;
}
function requestLowDay() public returns (bytes32 requestID)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); //Error occur here
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
request.add("path", "RAW.ETH.USD.LOWDAY");
int timesAmount = 10**2;
request.addInt("times", timesAmount);
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfill(bytes32 _requestId, uint256 _dayLow) public recordChainlinkFulfillment(_requestId)
{
lowDay = _dayLow;
}
function requestHighDay() public returns (bytes32 requestID)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); //Error occur here
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
request.add("path", "RAW.ETH.USD.HIGHDAY");
int timesAmount = 10**2;
request.addInt("times", timesAmount);
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfill(bytes32 _requestId, uint256 _dayHigh) public recordChainlinkFulfillment(_requestId)
{
highDay = _dayHigh;
}
function withdrawLink() external
{
LinkTokenInterface linkToken = LinkTokenInterface(chainlinkTokenAddress());
require(linkToken.transfer(msg.sender, linkToken.balanceOf(address(this))), "Unable to transfer");
}
}
基本代码不是我写的,它与“VOLUME24HOUR”调用完美配合。当我对 request.add("path") 进行必要的更改并添加新变量 lowDay/highDay 时,它开始抛出错误。
谢谢 ʕっ•ᴥ•ʔっ
Solidity 变量名称区分大小写。
您已经定义了一个名为 jobID
(大写 D
)的 bytes32
属性,但是您试图传递 jobId
(小写 d
).
解决方法:传递正确的区分大小写的变量名。在你的情况下 jobID
.
我是 Solidity 的新手,目前,我正在尝试部署一个简单的智能合约,请求 ETH 价格 “LOWDAY” 和“HIGHDAY”。我已经做了一个非常相似的 SC,它只请求“VOLUME24HOUR”,而且效果很好。这是我得到的错误:
contracts/API_Consumer_Info.sol:24:66: DeclarationError: Undeclared identifier. Did you mean "jobID"? Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
^---^
pragma solidity ^0.6.7;
import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumerInfo is ChainlinkClient
{
uint256 public lowDay;
uint256 public highDay;
address private oracle;
bytes32 private jobID;
uint256 private fee;
constructor() public
{
setPublicChainlinkToken();
oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
jobID = "29fa9aa13bf1468788b7cc4a500a45b8";
fee = 0.1 * 10 ** 18;
}
function requestLowDay() public returns (bytes32 requestID)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); //Error occur here
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
request.add("path", "RAW.ETH.USD.LOWDAY");
int timesAmount = 10**2;
request.addInt("times", timesAmount);
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfill(bytes32 _requestId, uint256 _dayLow) public recordChainlinkFulfillment(_requestId)
{
lowDay = _dayLow;
}
function requestHighDay() public returns (bytes32 requestID)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); //Error occur here
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
request.add("path", "RAW.ETH.USD.HIGHDAY");
int timesAmount = 10**2;
request.addInt("times", timesAmount);
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfill(bytes32 _requestId, uint256 _dayHigh) public recordChainlinkFulfillment(_requestId)
{
highDay = _dayHigh;
}
function withdrawLink() external
{
LinkTokenInterface linkToken = LinkTokenInterface(chainlinkTokenAddress());
require(linkToken.transfer(msg.sender, linkToken.balanceOf(address(this))), "Unable to transfer");
}
}
基本代码不是我写的,它与“VOLUME24HOUR”调用完美配合。当我对 request.add("path") 进行必要的更改并添加新变量 lowDay/highDay 时,它开始抛出错误。
谢谢 ʕっ•ᴥ•ʔっ
Solidity 变量名称区分大小写。
您已经定义了一个名为 jobID
(大写 D
)的 bytes32
属性,但是您试图传递 jobId
(小写 d
).
解决方法:传递正确的区分大小写的变量名。在你的情况下 jobID
.