To query prices from Connect oracle on MoveVM, you need to use the oracle module in InitiaStdLib found at 0x1::oracle (explorer link).

This module provides a get_price function that you can use to fetch the price of an asset pair. The asset pair is specified using the pair_id, which is a string of the format "ASSET1/ASSET2". For example, the example module below fetches the price of BTC/USD from Connect oracle.

module example::examples {
    use std::string::String;
    use initia_std::oracle::get_price;

    #[view]
    public fun get_price_example(pair_id: String): (u256, u64, u64) {
        let (price, timestamp, decimals) = get_price(pair_id);
        (price, timestamp, decimals)
    }

    #[test]
    public fun test_get_price_example(): (u256, u64, u64) {
        let btc_usd_pair_id = string::utf8(b"BITCOIN/USD"); 
        let (price, timestamp, decimals) = get_price_example(btc_usd_pair_id);
        (price, timestamp, decimals)
    }
}

The response from the get_price function is then a tuple of (price, timestamp, decimals), where:

  • price is the price of the asset pair multiplied by 10decimals10^{decimals}
  • timestamp is the timestamp of the last update
  • decimals is the number of decimals in the price