Usage

The Oracle maintains updates as a mapping, where each key maps to a Data struct containing the latest timestamp and value.

The updates mapping is a key-value store where:

  • Key: A unique identifier, typically a string, representing the asset or data type (e.g., DIA/USD, BTC/USD).

  • Value: A Data struct containing:

    • key: The identifier of the data entry (redundant for reference but useful for integrity checks).

    • timestamp: The timestamp of the latest update.

    • value: The most recent value associated with the key.

E.g. PriceConsumer contract

contract PriceConsumer {
    Oracle public oracle;

    constructor(address _oracle) {
        oracle = Oracle(_oracle);
    }

    function getLatestPrice(string memory _key) public view returns (uint128) {
        return oracle.updates(_key).value;
    }
}

You can find demo oracles here. If you want to access the oracle on Ethereum Sepolia for example, you’ll pass the Push Oracle address: 0x76a4BA6e4A40Bc613821e2a468a1e94FcCa4CE83 to the constructor above.