我遵循Chainlink docs初级教程中的步骤,如下所述:
https://docs.chain.link/docs/beginners-tutorial/
在最后一段之前,一切似乎都正常:
点击"getLatestPrice",看看!最新的价格就出现在按钮下面。我们已经成功地部署了一个智能合同,它使用Chainlink价格提要,到Kovan Ethereum测试网!
相反,当我单击"getLatestPrice“时,Remix的输出窗口显示:
调用PriceConsumerV3.调用PriceConsumerV3.错误:
有人知道我做错了什么吗?
谢谢!
发布于 2021-06-12 05:48:05
这似乎是一个特定于Remix的错误。我复制了你所做的,通过Remix把它部署到Kovan上,得到了同样的错误。然后,在验证合同之后,我尝试使用Etherscan接口读取数据,一切都很好。
合同代码:https://kovan.etherscan.io/address/0x31C09Eaf8bA8D8FC9Ab044896F870cD737617FF6#readContract
用于以太扫描验证的扁平实性代码:
pragma solidity ^0.6.7;
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Kovan
* Aggregator: ETH/USD
* Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
*/
constructor() public {
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
}
/**
* Returns the latest price
*/
function getLatestPrice() public view returns (int) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
return price;
}
}
更新:我向Remix https://github.com/ethereum/remix-project/issues/1282提交了这个问题
发布于 2021-06-12 07:48:47
您正在获得错误[object Object]
,因为您使用的是javascript提供程序,它不能与kovan上的其他契约交互,它只能与部署在同一个浏览器中的其他联系人交互。
在部署时,将web3提供程序从Javascript VM
切换到Injected Web3
,并将元问题连接到kovan
https://ethereum.stackexchange.com/questions/101760
复制相似问题