TypeError: Type type(contract AggregatorV3Interface) is not implicitly convertible to expected type contract AggregatorV3Interface.
--> contracts/FundMe.sol:21:10:
|
21 | AggregatorV3Interface priceFeed = AggregatorV3Interface;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here’s my code:
function getVersion() internal view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface;
return priceFeed.version();
}
i dont know i still cant figure that out
1
An interface
type in Solidity always accepts one argument – the contract address that you expect to implement this interface (and want to call later on).
Here’s an example – address from the Chainlink docs page applied to your code:
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43);
There’s multiple Chainlink price feeds – one for ETH price, one for BTC price, one for another token, etc. Each of them is a contract deployed on a different address. But all of them implement the same interface. By passing the price feed contract as the argument, you’re telling your contract from which target contract it should read the data.
This can be applied not only to Chainlink but to Solidity interfaces in general. You might have an interface that declares a function greet()
. Contract on address 1 might return “Hello” and contract on address 2 might return “Hi” from the function with the same name. But since the function name is the same in both, they both implement the same interface, and your contract can decide whether it wants to call greet()
on the address 1 (returning “hello”) or on the address 2 (returning “hi”).