Interacting with Oracle on MoveVM

Overview

This tutorial guides you through fetching oracle prices in a Move on Minitia environment utilizing the 0x1::oracle modules. By following this tutorial, developers can understand how to integrate and retrieve real-time financial data within their smart contracts on the Minitia blockchain.

Prerequisites for L2s

Enabling Oracles

Sample Contract Implementation

GetPrice

Using 0x1::oracle::get_price, one can fetch prices from the oracle.

#[view]
public fun get_price(pair_id: String): (u256, u64, u64) {
    get_price_internal(*string::bytes(&pair_id))
}
  • pair_id: {Base}/{Quote} format string. through the following lcd query, you can check the available pairs: {LCD_URI}/slinky/oracle/v1/get_all_tickers

  • response: (price, update_at, decimals)

    • price is before applying decimals. for example, if the price is 123456789 and decimalsis 3, the real price is 123456.789.

    • update_at is a UNIX time when the price was updated.

Conclusion

This section provides a foundation for integrating real-time oracle data into your blockchain applications, leveraging Cosmos-based oracles within an Move context. It's suitable for financial applications requiring access to up-to-date currency prices and can be expanded or modified to fit specific requirements or additional functionalities.

Last updated

Logo

© 2024 Initia Foundation, All rights reserved.