Lesson 4: Interfaces & Price Feeds - how would we know that a parameter can be passed into the AggregatorV3Interface constructor? #1864
-
Hi, In this line, AggregatorV3Interface priceFeed = AggregatorV3INterface(0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
AggregatorV3Interface is an external library that takes that smart contract address. Suppose you want to know the price of Eth in terms of USD (ETH/USD) you take the address of the smart contract from the chainlink that referred to (ETH/USD) and you can use this address as a parameter inside AggregatorV3Interface and get the price. |
Beta Was this translation helpful? Give feedback.
-
Hey @nsawit As we all know, interfaces allow us to talk to other contracts on the blockchain by just writing the function signatures without specifying the implementation of these function. When defining interfaces, we just write the functions we expect to call from the other contract and disregard their implementation altogether. In your case, we want to talk to a data feed that will give us the price of ethereum, so we "create" an interface for it. However, chainlink already created the interface for this contract and named it Okay now we have the interface, we need to have the address of the contract we want to interact with and in this case, we go to the chainlink documentation to learn more about the contract that gives us the data feed. If you go to ethereum data feeds in the chainlink documentation, you'll see a bunch of addresses where these contracts are hosted on different chains. In this case we are interested with ETH/USD conversion on goerli network so we are given the address 0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e. Remember the interface we created? it was just a skeleton, the real contract is in this address and for us to use the interface, we need to read the main contract first so we know what else is needed that isn't contained in interface. Reading the contract, we discover on line 139 that it has a constructor function that takes in an address parameter. So that's why we pass an address in the interface. To learn more about how we interact with this contract and pass the address argument, you simply go back to the chainlink documentation section titled Using Datafeeds In the solidity subsection, we see that we see exactly how we can pass the address and retrieve the price of ETH in USD. TL;DR |
Beta Was this translation helpful? Give feedback.
Hey @nsawit As we all know, interfaces allow us to talk to other contracts on the blockchain by just writing the function signatures without specifying the implementation of these function. When defining interfaces, we just write the functions we expect to call from the other contract and disregard their implementation altogether. In your case, we want to talk to a data feed that will give us the price of ethereum, so we "create" an interface for it. However, chainlink already created the interface for this contract and named it
AggregatorV3Interface
instead of copying and pasting this interface in our contract, we just import it from the github repo.Okay now we have the interface, we ne…