Lesson 4: Declaration Error: Undeclared Identifier #2257
-
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
Please attach a screenshot of the error with code |
Beta Was this translation helpful? Give feedback.
-
@rarddd Problem lies here: function getVersion() public view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(0xAc559F25B1619171CbC396a50854A3240b6A4e99);
return priceFeed.version();
return uint256(price * 1e10);
} In the above, remove the extraneous |
Beta Was this translation helpful? Give feedback.
-
@rarddd Provide more info about the error, I am seeing that you are using a different address, are you using a different ETH/USD address than Rinkeby because it is different? And second thing, you are returning multiple times in getVersion function. |
Beta Was this translation helpful? Give feedback.
-
Hey @rarddd I'm seeing there is a problem in the function declaration here
You've said your function will return one |
Beta Was this translation helpful? Give feedback.
-
Hey @rarddd there's a couple issues with your code as it is. The error you are getting here
In the end, you code should look like this. // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
// Why is this a library and not abstract?
// Why not an interface?
library PriceConverter {
// We could make this public, but then we'd have to deploy it
function getPrice() internal view returns (uint256) {
// Rinkeby ETH / USD Address
// https://docs.chain.link/docs/ethereum-addresses/
AggregatorV3Interface priceFeed = AggregatorV3Interface(
0x8A753747A1Fa494EC906cE90E9f37563A8AF630e
);
(, int256 answer, , , ) = priceFeed.latestRoundData();
// ETH/USD rate in 18 digit
return uint256(answer * 10000000000);
}
// 1000000000
function getConversionRate(uint256 ethAmount) internal view returns (uint256) {
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
// the actual ETH/USD conversion rate, after adjusting the extra 0s.
return ethAmountInUsd;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./PriceConverter.sol"; // Importing the library file
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract FundMe{
using PriceConverter for uint256; // Attaching the library file into our
uint256 public minimumUsd = 50 * 1e18;
address[] public funders;
mapping(address => uint256) public addressToAmountFunded;
function fund() public payable{
require (msg.value.getConversionRate() >= minimumUsd, "Didn't send enough");
funders.push(msg.sender);
addressToAmountFunded[msg.sender] = msg.value;
}
function getVersion() public view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(0xAc559F25B1619171CbC396a50854A3240b6A4e99);
return priceFeed.version();
// Remove this: return uint256(price * 1e10);
}
//function withdraw(){}
} Try this and tell me if it works. |
Beta Was this translation helpful? Give feedback.
Hey @rarddd there's a couple issues with your code as it is. The error you are getting here
require (msg.value.getConversionRate() >= minimumUsd, "Didn't send enough");
is because you are trying to use the.getConversionRate()
as if it were a library function attached to the type uint256 which in your case, you haven't attached any library function on the uint256 type.So to make this work, you're gonna have to do a couple things.
FundMe.sol
and move all the price conversion functionalities (getPrice()
,getConversionRate()
) into another file in the form of a libraryFundMe.sol
u…