[英]Why is Chainlink oracle function call failing?
在嘗試為我提供資金時,合同告訴我它遇到了一個錯誤,但沒有具體說明錯誤。 我試圖通過基金 function 資助 0.1 eth,並在終端中顯示:
[block:8404521 txIndex:12]
from: 0x8a9...e4303
to: FundMe.fund() 0x542...E109C
value: 100000000000000000 wei
data: 0xb60...d4288
logs: 0
hash: 0x29a...97939
在 etherscan 中它說:狀態失敗:
Contract 0x5422f3458be343e378e7a399e16fff548e7e109c
Warning! Error encountered during contract execution [execution reverted]
我試着尋找我的代碼的問題,但沒有找到。
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.6 <0.9.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
//import "@chainlink/contracts/src/v0.8/vendor/SafeMathChainlink.sol"; won't need in later complier versions.
contract FundMe {
mapping(address => uint256) public addressToAmountFunded;
function fund() public payable {
uint256 minimumUSD = 50 * 10 ** 18;
require( getConversionRate(msg.value) >= minimumUSD,"You need to send more Eth");
addressToAmountFunded[msg.sender] += msg.value;
}
function getVersion() public view returns (uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
return priceFeed.version();
}
function getPrice() public view returns (uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
(,int256 answer,,,)=priceFeed.latestRoundData();
return uint256(answer * 10000000000);
}
//10000000000 = Gwei which is why we added 10 zeros to getPrice(answer) to convert it to Wei amount
function getConversionRate(uint256 ethAmount) public view returns (uint256){
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount)/ 1000000000000000000; //divide 2x because we added 10*((getPrice)answer))
return ethAmountInUsd;
}
}
從這里獲取ETH/USD
goerli tes.net地址:“0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e”
現在為了調用 chainlink oracle 你必須在你的合約中有LINK
代幣。 從水龍頭獲取一些鏈接令牌到您的合同地址
在元掩碼中導入令牌。 你會看到金額
將鏈接令牌從您的元掩碼發送到您的合約
部署你的合約。 如果您使用的是Remix IDE
,則選擇injected provider
連接到元掩碼。 因為chainlink合約是在歌爾力上的,所以你需要在歌爾力tes.net上。 部署完成后,您可以致電fund
function。
由於fund
function 沒有參數,您需要在交易時發送價值。 這就是為什么在 function 中你有msg.value
來訪問發送的數量。
在Remix
ide 中,在“GAS LIMIT input there is
VALUE input. you need to pass the amount in there before you call the
function。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.