Chainlink

Chainlink 初學者教程:呼叫 PriceConsumerV3.getLatestPrice 出錯:objectObject這bj和C噸這bj和C噸object Object

  • June 12, 2021

我已按照 Chainlink docs Beginner’s tutorial 中的步驟進行操作,如下所述:

https://docs.chain.link/docs/beginners-tutorial/

一切似乎都有效,直到最後一段:

點擊“getLatestPrice”,瞧!最新價格出現在按鈕下方。我們已成功將使用 Chainlink 價格資訊的智能合約部署到 Kovan 乙太坊測試網!

相反,當我點擊“getLatestPrice”時,Remix 的輸出視窗會顯示:

呼叫 PriceConsumerV3.getLatestPrice 呼叫

PriceConsumerV3.getLatestPrice 錯誤:

$$ object Object $$

有誰知道我做錯了什麼?

謝謝!

這似乎是特定於 Remix 的錯誤。我複制了你所做的,通過 Remix 將其部署在 Kovan 上,並得到了同樣的錯誤。然後,我在驗證合約後嘗試使用 Etherscan 介面讀取該數據,一切正常。

合約程式碼:https ://kovan.etherscan.io/address/0x31C09Eaf8bA8D8FC9Ab044896F870cD737617FF6#readContract

用於 Etherscan 驗證的扁平化 Solidity 程式碼:

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

您收到錯誤[object Object]是因為您使用的是 javascript VM 提供程序,它無法與 kovan 測試網上的其他合約互動,它只能與在同一瀏覽器中使用 remix 部署的其他聯繫人互動。

Javascript VM部署時從左側面板切換 web3 提供程序Injected Web3,並保持您的元遮罩連接到 kovan

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