Shop already holds the address of a PriceFeed. Use it:
return quantity * feed.latestPrice();
Three units at 42 is 126. That is one contract calling another, and it is a real transaction hop under the hood.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// Pretend this one is already deployed and you cannot change it.
contract PriceFeed {
uint256 private price = 42;
function latestPrice() external view returns (uint256) {
return price;
}
}
contract Shop {
PriceFeed public feed;
constructor() {
feed = new PriceFeed();
}
function quote(uint256 quantity) external view returns (uint256) {
return quantity;
}
}