LESSON 7 : Error: invalid address (argument="address", value=undefined, code=INVALID_ARGUMENT, version=address/5.7.0) (argument="priceFeedAddress", value=undefined, code=INVALID_ARGUMENT, version=abi/5.7.0) #4890
-
Down are The Helper Hardhat config file and 00_deploy_mocks Down is the 01_deploy_fund_me Since the Error specifically highlights the "priceFeedAddress" that i used in FundMe.sol, below i will provide my FundMe.sol as well as PriceConverter.sol files. FundMe.sol // SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./PriceConverter.sol";
error NotOwner();
contract FundMe {
using PriceConverter for uint256;
mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
// Could we make this constant? /* hint: no! We should make it immutable! */
address public /* immutable */ i_owner;
uint256 public constant MINIMUM_USD = 50 * 10 ** 18;
AggregatorV3Interface public priceFeed;
constructor(address priceFeedAddress) {
i_owner = msg.sender;
priceFeed = AggregatorV3Interface(priceFeedAddress);
}
function fund() public payable {
require(msg.value.getConversionRate(priceFeed) >= 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);
}
modifier onlyOwner {
// require(msg.sender == owner);
if (msg.sender != i_owner) revert NotOwner();
_;
}
function withdraw() public onlyOwner {
for (uint256 funderIndex=0; funderIndex < funders.length; funderIndex++){
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
funders = new address[](0);
// // 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");
}
// Explainer from: https://solidity-by-example.org/fallback/
// Ether is sent to contract
// is msg.data empty?
// / \
// yes no
// / \
// receive()? fallback()
// / \
// yes no
// / \
//receive() fallback()
fallback() external payable {
fund();
}
receive() external payable {
fund();
}
} PriceConverter.sol // SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
library PriceConverter {
// We could make this public, but then we'd have to deploy it
function getPrice(
AggregatorV3Interface priceFeed
) internal view returns (uint256) {
// // Goerli ETH / USD Address
// // https://docs.chain.link/docs/ethereum-addresses/
// AggregatorV3Interface priceFeed = AggregatorV3Interface(
// 0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e // ETH/USD Price Feed Address depending on Goerli chain
// );
(, int256 answer, , , ) = priceFeed.latestRoundData();
// ETH/USD rate in 18 digit
return uint256(answer * 10000000000);
// or (Both will do the same thing)
// return uint256(answer * 1e10); // 1* 10 ** 10 == 10000000000
}
// 1000000000
function getConversionRate(
uint256 ethAmount,
AggregatorV3Interface priceFeed
) internal view returns (uint256) {
uint256 ethPrice = getPrice(priceFeed);
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
// or (Both will do the same thing)
// uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1e18; // 1 * 10 ** 18 == 1000000000000000000
// the actual ETH/USD conversion rate, after adjusting the extra 0s.
return ethAmountInUsd;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I noticed that in my helper-hardhat-config.js , the variable name of polygon address is different from Goerli, but even after correcting that issue, i get the same Invalid Address error. |
Beta Was this translation helpful? Give feedback.
-
Hi @jatin-choubey. Could you try adding quotes around the addresses in As the little dots suggest it, it is not a correct way to write an address in JavaScript. In Solidity, the const networkConfig = {
5: {
name: 'goerli',
ethUsdPriceFeed: '0xd4a...8e'
},
137: {
// Same here
}
} Let me know if it solves the issue! |
Beta Was this translation helpful? Give feedback.
Hi @jatin-choubey. Could you try adding quotes around the addresses in
networkConfig
, forethUsdPriceFeed
andethUsdPrice
?As the little dots suggest it, it is not a correct way to write an address in JavaScript. In Solidity, the
address
type allows you to write addresses like this, but in JavaScript it should be written as strings.Let me know if it solves the issue!