-
Hi, I tried everything in order to be able to fund my contract with 5-6 Ether but it is not working and not working, I tried to paste the exact codes from the section but still it reverts, I tried to make the constructor payable and it was the only thing that was able to work out, do you have any ideas what might be wrong? Those are the 2 codes: import {AggregatorV3Interface} from "@chainlink/contracts@1.2.0/src/v0.8/shared/interfaces/AggregatorV3Interface.sol"; library PriceConverter {
} import {AggregatorV3Interface} from "@chainlink/contracts@1.2.0/src/v0.8/shared/interfaces/AggregatorV3Interface.sol"; import "./PriceConverter.sol"; // constant, immutable error NotOwner();
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 16 replies
-
Hello @ustisa, Please run your code with the |
Beta Was this translation helpful? Give feedback.
-
I reviewed your code and it seems correct. With this information I can't guess what your issue might be. send a picture that shows the details. |
Beta Was this translation helpful? Give feedback.
-
@ustisa If you're using remix remove the version from your imports import {AggregatorV3Interface} from "@chainlink/contracts@1.2.0/src/v0.8/shared/interfaces/AggregatorV3Interface.sol" to import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol" what are you trying to do here in the constructor? msg.value.getConversionRate(); // Does nothing dont make you constructor payable, you dont need it here! AggregatorV3Interface priceFeed = AggregatorV3Interface(0x694AA1769357215DE4FAC081bf1f309aDC325306); once you have deployed on sepolia try to call the fund function sending this value ( 0.005 ETH): 5000000000000000 your code reviewed // SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
import {PriceConverter} from "./PriceConverter.sol"; //<-- named import please
// constant, immutable
error NotOwner();
contract FundMe{
using PriceConverter for uint256;
address[] public funders;
mapping (address funder => uint256 amountFunded) public addressToAmountFunded;
address public immutable i_owner;
uint256 public constant MINIMUM_USD = 5 * 10 ** 18;
// 2552 gas
// 439 gas
constructor() {
i_owner = msg.sender;
}
function fund() public payable{
require(msg.value.getConversionRate() >= MINIMUM_USD,"Did not send enough ETH");
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender);
}
// // function fund() public payable {
// require(msg.value.getConversionRate() >= MINIMUM_USD, "You need to spend more ETH!");
// // require(PriceConverter.getConversionRate(msg.value) >= MINIMUM_USD, "You need to spend more ETH!");
// addressToAmountFunded[msg.sender] += msg.value;
// funders.push(msg.sender);
function getVersion() public view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x694AA1769357215DE4FAC081bf1f309aDC325306);
return priceFeed.version();
}
function withdraw() public onlyOwner{
// SINGLE = - SET
// DOUBLE == - IS
// for(/* starting index, ending index, step amount */)
for(uint256 funderIndex =0; funderIndex < funders.length; funderIndex++){
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
funders = new address[](0);
(bool callSuccess, ) = payable(msg.sender).call{value: address(this).balance}("");
require(callSuccess, "Call failed");
// payable(msg.sender).transfer(address(this).balance);
}
modifier onlyOwner() {
// require(msg.sender == owner);
if (msg.sender != i_owner) revert NotOwner();
_;
}
receive() external payable {
fund();
}
fallback() external payable {
fund();
}
} |
Beta Was this translation helpful? Give feedback.
because we are hard coding the datafeed which works only on sepolia.