Lesson 4 #5196
-
TESTNET DEMO When i want to deploy contract from goerli network in MetaMask throwing error: You do not have enough GoerliETH in your account to pay for transaction fees on Goerli network. or deposit from another account. But I have 0.132GoerliETH; When I try to do with Sepolia I deploy contract, but can't send eth... But I can send from Goerli. Also I can sent less than 50 usd but the contract runs nonetheless. Maybe someone understand and can help? FUNDME import "./PriceConverter.sol";
contract FundMe {
using PriceConverter for uint256;
uint256 public minimumUsd = 50 * 1e18; // 1 * 10 ** 18
address[] public funders;
mapping(address => uint256) public addressToAmountFunded;
address public owner;
constructor(){
owner = msg.sender;
}
function fund() public payable{
require(msg.value.getConversionRate() >= minimumUsd,"Didn't send enough!"); //1e18 == 1 * 10 ** 18 == 1000000000000000000
funders.push(msg.sender);
addressToAmountFunded[msg.sender] += msg.value;
}
function Withdraw() public {
/* starting index, ending index, step amount */
for(uint256 funderIndex = 0; funderIndex < funders.length; funderIndex = funderIndex++){
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
// reset the array
funders = new address[](0);
// actually withdraw the funds
//transfer
// payable(msg.sender).transfer(address(this).balance);
//send
// bool sendSuccess = payable(msg.sender).send(address(this).balance);
// require(sendSuccess, "Send failed");
//call
(bool callSuccess, ) = payable(msg.sender).call{value: address(this).balance} ("");
require(callSuccess, "Call failed");
}
modifier onlyOwner {
require(msg.sender == owner, "Sender is not owner!");
_;
} PRICECONVERTER import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
library PriceConverter {
function getPrice() internal view returns(uint256) {
//ABI
//Adress 0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e
AggregatorV3Interface priceFeed = AggregatorV3Interface(0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e);
(,int256 price,,,) = priceFeed.latestRoundData();
//ETH in terms of USD
//mažiau nei 3000.00000000
return uint256(price * 1e10); //1**10 == 10000000000
}
function getConversionRate(uint256 ethAmount) internal view returns (uint256) {
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1e18;
return ethAmountInUsd;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@Neriauk Use sepolia, and it is not working on sepolia because you are using the price feed address of goerli, you should use the sepolia price feed address, check the address in chainlink docs. |
Beta Was this translation helpful? Give feedback.
@Neriauk Use sepolia, and it is not working on sepolia because you are using the price feed address of goerli, you should use the sepolia price feed address, check the address in chainlink docs.