I am testing this code on Remix:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Kovan
* Aggregator: ETH/USD
* Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
*/
constructor() {
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;
}
}
Compilation and deployment seem to be executed correctly, however I receive this error:
call to PriceConsumerV3.getLatestPrice errored: Returned error: VM Exception while processing transaction: revert
Any suggestion?
I've seen this error when deploying to the Javascript VM
It's due to the contract you are trying to call not being available on the VM you are using. You'll need to switch to the Injected Web3 option.
The deployment will also require having a wallet set up as you interact with an actual blockchain. The example you reference is using the Kovan Tes.net.
Here are a few other links for reference
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.