This tutorial guides you through fetching oracle prices in a WasmVM on Minitia environment utilizing stargate query. By following this tutorial, developers can understand how to integrate and retrieve real-time financial data within their smart contracts on the Minitia blockchain.
Using thewasm-slinky-query repository, you can fetch oracle prices through a CosmWasm contract.
In this section, we'll provide an example contract and show how to deploy it so that you can call stargate query or directly implement it in your contract.
Get All Currency Pairs
Function to fetch all currency pairs available from the oracle.
fnget_all_currency_pairs(&self, deps:Deps, _env:Env) ->StdResult<GetAllCurrencyPairsResponse> {let request =GetAllCurrencyPairsRequest { special_fields:::protobuf::SpecialFields::new() };let bytes = request.write_to_bytes().unwrap();let data =Binary::from(bytes); let request = QueryRequest::<Empty>::Stargate{path: "/slinky.oracle.v1.Query/GetAllCurrencyPairs".to_string(), data};
let res:GetAllCurrencyPairsResponse= deps.querier.query(&request)?;Ok(res)}#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]#[allow(non_snake_case)]pubstructCurrencyPair {pubBase:String,pubQuote:String,}
Get Price
Function to fetch the price of a specific currency pair. pair_id is in a format of {Base}/{Quote} .
This contract provides a foundation for integrating real-time oracle data into your blockchain applications, leveraging Cosmos-based oracles within an WasmVM 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.