SOCI4L

Talk to a contract you did not write

Step 1 of 4
0 of 2 goals

Ask it for the price

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;
    }
}

Goals

The contract compiles
nothing to compile yet
`quote(3)` reads back 126
the contract has not run yet

Contract storage

Write a contract and it will deploy itself here.