Closed olekmorawski closed 1 year ago
Everything you have posted here seems fine. The error you are getting is likely because you have not converted the eth/usd price to 18 digits. In your PriceCoverter contract you need to multiply the eth/usd price by 10**10 since the eth/usd price you initially get have only 8 additional zeros. If your eth/usd price do not have 18 digits then you end up checking for way too much USD rather than 50.
Everything you have posted here seems fine. The error you are getting is likely because you have not converted the eth/usd price to 18 digits. In your PriceCoverter contract you need to multiply the eth/usd price by 10**10 since the eth/usd price you initially get have only 8 additional zeros. If your eth/usd price do not have 18 digits then you end up checking for way too much USD rather than 50.
This is how My price converter looks like and i cant see anything wrong with it. I have to say, moments like this really discourage me from thinking that i could become a solidity dev. Just because of how helpless i feel - especially when i dont think that anything is wrong with my code. Thanks for help btw
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
library PriceConverter {
function getPrice(AggregatorV3Interface priceFeed)
internal
view
returns (uint256)
{
(, int256 price, , , ) = priceFeed.latestRoundData();
// ETH in USD
return uint256(price * 1e10);
}
function getConversionRate(
uint256 ethAmont,
AggregatorV3Interface priceFeed
) internal view returns (uint256) {
uint256 ethPrice = getPrice(priceFeed);
uint256 ethAmontInUSD = (ethPrice * ethAmont) / 1e18;
return ethAmontInUSD;
}
}
Everything seems fine to me as well, did you try sending more ether than 1 and see if its pass? And don't be discourage, even professional developer goes through problems for days, totally normal. You will eventually solve this problem and probably gonna realize how silly mistake it was.
Everything seems fine to me as well, did you try sending more ether than 1 and see if its pass? And don't be discourage, even professional developer goes through problems for days, totally normal. You will eventually solve this problem and probably gonna realize how silly mistake it was.
I tried sending 10 and it gives me the same error. I'm totally confused. The only thing i can think of is to start over the whole project... :(
I also tried to debug it with remix and remix prints me an error like this : creation of FundMe errored: Error encoding arguments: Error: invalid address (argument="address", value="", code=INVALID_ARGUMENT, version=address/5.5.0) (argument=null, value="", code=INVALID_ARGUMENT, version=abi/5.5.0)
Maybe its that pricefeedaddress thats here empty in remix? and thats the reason why it does not work?
Okay so im a noob and remix only deploys contracts and i have no way of testing them with js so the fact i got it runnin there does not matter because thats not the problem, the test seems to be off the...i dont know im confused
Maybe its that pricefeedaddress thats here empty in remix? and thats the reason why it does not work?
Yes, you will need a pricefeed address from chainlink data feeds and pass it in constructor
Maybe its that pricefeedaddress thats here empty in remix? and thats the reason why it does not work?
Yes, you will need a pricefeed address from chainlink data feeds and pass it in constructor
Yeah i figured that out, does not help my test tho :(. I think im going to start all over
Maybe its that pricefeedaddress thats here empty in remix? and thats the reason why it does not work?
Yes, you will need a pricefeed address from chainlink data feeds and pass it in constructor
Yeah i figured that out, does not help my test tho :(. I think im going to start all over
Maybe delete artifacts and cache and then run again or Maybe clone the project and try to run test and see what 's different
Maybe its that pricefeedaddress thats here empty in remix? and thats the reason why it does not work?
Yes, you will need a pricefeed address from chainlink data feeds and pass it in constructor
Yeah i figured that out, does not help my test tho :(. I think im going to start all over
Maybe delete artifacts and cache and then run again or Maybe clone the project and try to run test and see what 's different
Hey if anyone here is curious to see my weird errors i have pushed my repo on git here : https://github.com/olekmorawski/hardhat-fund-me-fcc
Feel free to check this out and lmk if anyone managed to fix it or know what the problem might be. The problem still persists in the repo
You are passing 1 eth = 2 usd in your MockV3Aggregator constructor when you are deploying mocks. so passing 1 eth will check 2 usd >= MINIMUM_USD and fails. In your helper-hardhat-config you can change the INITITAL_ANSWER from 200000000 to 20000000000. It's 8 decimals so you are setting ETH/USD to 2 , add 3 zeros so it will be 2000 USD, now 50/2000 = 0.025. Now your test will pass even if you send 0.025 ETH.
And one more thing, since you have install hardhat-toolbox plugin and imported it in your hardhat.config.js, you can remove any of these imports, they all redundant now:
@nomiclabs/hardhat-ethers
@nomiclabs/hardhat-etherscan
hardhat-gas-reporter
solidity-coverage
@typechain/hardhat
You can read it on https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-toolbox
oh yeah! it fixed the problem! thanks man!
Can someone please help me? I tried debugging it on my own for like 3 hours now and im losing my mind over it now. I get an error while testing :
This is my FundMe.test.js:
This is my FundMe.sol: