Skip to main content

Consuming Oracle Data

Chronicle oracles are read-protected by a whitelist, meaning you won't be able to read them on-chain without your address being added to the whitelist.

info

On Testnet, the SelfKisser contract allows users to whitelist themselves, whimsically termed 'kiss' themselves.

On Mainnet, to get access to production Oracles, please open a ticket on Discord via the 🆘 | support channel.

Testnet NetworkSelfKisser Address
Ethereum Sepolia0x9eE458DefDc50409DbF153515DA54Ff5B744e533
Base Sepolia0x7D62Def8478c21B82aA7fcbc2E7f8B404Ac6c565
Arbitrum Sepolia0x4BAe02bED4b49DE3344878b0B0B2d6A58D47ddC5
Gnosis Mainnet0xE24c5cd952193eDA44BE71c19b35a9CB83cd1E24
Mantle Testnet0x165dC3e99E3491b8914CF65b4CBC4E98755da53e
Scroll Sepolia0xCE26246F859512CD22faE6037fb0371960B68a0C
zkSync Sepolia0x8253Bb923473E84D0C0013F3742D2F4E49D9f4eb
Optimism Sepolia0x84c2dD149026327f95A7947d788Dff49D8B24E26
Berachain Bepolia0x584914a893aBefB95abC02A5604338c0390F328B
Superseed Sepolia0x174d08990e95aa7C025cA7B44e41768c15616041
Plume Testnet0xd6de00f82738c966c88F55017e8aCcA192AF42a1
Monad Testnet0xFdDB9A201d8E0E7fF6Fe835cfa0105efe6275EA1
Unichain Sepolia0x7AB42CC558fc92EC990B22E663E5a7bc5879fc9f
Avalanche Fuji Testnet0x371A53bB4203Ad5D7e60e220BaC1876FF3Ddda5B
Linea Testnet0xBa1386329Dea3850Aedc07D387014494619F615D
Plasma Testnet0xB3bf22c657a2d1EDEf447CA8D863C10989e047B0

Consuming Oracle Data (Remix)​

An example contract named OracleReader.sol allows you to consume Oracle data and can be quickly deployed on Remix. Remix is a web-based integrated development environment (IDE) for creating, running, and debugging smart contracts directly in your browser.

info
  • In the table above you can find the address of the SelfKisser on different chains.
  • Addresses in this contract are hardcoded for the Sepolia testnet.
  • For other supported networks, please check the Dashboard, under the Testnets tab.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

/**
* @title OracleReader
* @notice A simple contract to read from Chronicle oracles
* @dev To see the full repository, visit https://github.com/chronicleprotocol/OracleReader-Example.
* @dev Addresses in this contract are hardcoded for the Sepolia testnet.
* For other supported networks, check the https://chroniclelabs.org/dashboard/oracles.
*/
contract OracleReader {
/**
* @notice The Chronicle oracle to read from.
* Chronicle_ETH_USD_3:0xdd6D76262Fd7BdDe428dcfCd94386EbAe0151603
* Network: Sepolia
*/

IChronicle public chronicle = IChronicle(address(0xdd6D76262Fd7BdDe428dcfCd94386EbAe0151603));

/**
* @notice The SelfKisser granting access to Chronicle oracles.
* SelfKisser_2:0x9eE458DefDc50409DbF153515DA54Ff5B744e533
* Network: Sepolia
*/
ISelfKisser public selfKisser = ISelfKisser(address(0x9eE458DefDc50409DbF153515DA54Ff5B744e533));

constructor() {
// Note to add address(this) to chronicle oracle's whitelist.
// This allows the contract to read from the chronicle oracle.
selfKisser.selfKiss(address(chronicle));
}

/**
* @notice Function to read the latest data from the Chronicle oracle.
* @return val The current value returned by the oracle.
* @return age The timestamp of the last update from the oracle.
*/
function read() external view returns (uint256 val, uint256 age) {
(val, age) = chronicle.readWithAge();
}
}

// Copied from [chronicle-std](https://github.com/chronicleprotocol/chronicle-std/blob/main/src/IChronicle.sol).
interface IChronicle {
/**
* @notice Returns the oracle's current value.
* @dev Reverts if no value set.
* @return value The oracle's current value.
*/
function read() external view returns (uint256 value);

/**
* @notice Returns the oracle's current value and its age.
* @dev Reverts if no value set.
* @return value The oracle's current value using 18 decimals places.
* @return age The value's age as a Unix Timestamp .
* */
function readWithAge() external view returns (uint256 value, uint256 age);
}

// Copied from [self-kisser](https://github.com/chronicleprotocol/self-kisser/blob/main/src/ISelfKisser.sol).
interface ISelfKisser {
/// @notice Kisses caller on oracle `oracle`.
function selfKiss(address oracle) external;
}

Ensure your environment is set to Remix VM - Sepolia Fork (since this example is hardcoded for Sepolia).

remix deploy image

Deploy the OracleReader.sol contract and you should see the following:

  • chronicle: returns 0xdd6D76262Fd7BdDe428dcfCd94386EbAe0151603, which is the address of the Chronicle_ETH_USD_3 Oracle
  • read: returns the current price (3533995000000000000000) and its age (1718091840) at the moment of calling.

Note: the price uses 18 decimals, meaning that the actual price is 3533.995. Age uses Unix Timestamp, meaning that 1718091840 corresponds to 'Tue Jun 11 2024 07:44:00 GMT'.

  • selfKisser: returns the address of the SelfKisser 0x9eE458DefDc50409DbF153515DA54Ff5B744e533
Example of Connect to Web3 button