# Querying Oracle Data
# Introduction
This guide provides a step-by-step approach to querying exchange rate data from the Nibiru oracle module using both the Nibiru CLI (nibid
) and Rust-based CosmWasm smart contracts.
# Querying Oracle Data via Nibiru CLI
# 1. Query Exchange Rates
To retrieve the latest exchange rates, run the following command:
# Sample Response
# 2. Query Active Pairs
To get the list of active oracle pairs:
# Sample Response
# Querying Oracle Data in Rust (CosmWasm Contracts)
# Smart Contract Query Implementation
The following Rust contract implements a query function to fetch exchange rate data using Nibiru's Stargate query mechanism.
# Query Function
# Query Module
# Query Message Definitions
# Understanding the nibiru_std
Cargo Package
The nibiru_std
crate is a utility library for interacting with the Nibiru blockchain in CosmWasm smart contracts. It provides essential types and helper functions to facilitate queries and transactions. In the context of querying oracle data, we use:
nibiru_std::proto
: Contains protocol buffer definitions for interacting with Nibiru modules.nibiru::oracle::QueryExchangeRateRequest
: Represents a request to query exchange rates from the oracle module.NibiruStargateQuery
: A trait used for converting messages into Stargate-compatible queries, allowing CosmWasm contracts to interact with the Nibiru chain’s modules.
By leveraging these utilities, smart contracts can efficiently fetch real-time exchange rate data from the blockchain without implementing complex serialization logic.
# Related Documentation
For further exploration of Nibiru smart contracts and integrations, refer to:
These resources provide more in-depth explanations and examples on interacting with Nibiru's blockchain using both CLI and smart contracts.