执行以坚固性和混音恢复

发布于 2025-02-03 03:28:31 字数 725 浏览 4 评论 0原文

我已经通过使用链链接界面写了一个简单的代码,以获取ETH价格:

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";

contract ABI {

    AggregatorV3Interface internal priceFeed;

    constructor() public {
        priceFeed = AggregatorV3Interface(0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c);
    }

    function latestPrice() public view returns (int256) {
        (, int256 answer,,,) = priceFeed.latestRoundData();
        return answer;
    }

}

问题是什么时候由混音编译,没有问题,但是执行后,它会引发下面的错误:

致电ContractNamefunctionName errored:rececution descution

您认为问题是什么吗?

I've wrote a simple code for fetching ETH price by using Chainlink interfaces as below:

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";

contract ABI {

    AggregatorV3Interface internal priceFeed;

    constructor() public {
        priceFeed = AggregatorV3Interface(0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c);
    }

    function latestPrice() public view returns (int256) {
        (, int256 answer,,,) = priceFeed.latestRoundData();
        return answer;
    }

}

The problem is when is being compiled by Remix, it has no problem but after execution it throws the error below:

call to ContractName.FunctionName errored: execution reverted

Do you think what the problem is?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

善良天后 2025-02-10 03:28:31

因为您的问题未指定您正在运行脚本的网络,所以我假设您正在使用混音VM仿真器。

指定的链条 Contract 仅在Ethereerum Mainnet上都可以使用。任何其他网络(包括模拟器)都没有在此地址上部署此合同。

要使用Remix中的数据提要合同,您可以创建主网的本地叉,然后连接到IDE中的本地网络。

Because your question didn't specify on which network you're running the script, I'm assuming that you're using the Remix VM emulator.

The specified Chainlink contract is available on Ethereum mainnet only. Any other network (including the emulator) does not have this contract deployed on this address.

To use the data feed contract in Remix, you can create a local fork of the mainnet, and then connect to the local network in the IDE.

乙白 2025-02-10 03:28:31

环境更改为在Remix IDE中注入Web3,然后连接到metAmask。例如,如果您使用的是kovan网络使用文档

// 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;
    }
}

Change ENVIRONMENT to Injected Web3 in Remix IDE and connect to metamask. For example, if you are using Kovan network use address as mentioned in the docs.

// 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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文