Crates.io | pyth-sdk-cw |
lib.rs | pyth-sdk-cw |
version | 1.2.0 |
source | src |
created_at | 2022-07-14 14:02:37.035655 |
updated_at | 2023-05-18 18:31:26.92753 |
description | Data structures and utilites for the Pyth price oracle |
homepage | https://pyth.network |
repository | https://github.com/pyth-network/pyth-crosschain |
max_upload_size | |
id | 625713 |
size | 11,977 |
This crate exposes utilities to interact with the contract on the CosmWasm ecosystem. You can also look at the example contract which demonstrates how to read price feeds from on-chain CosmWasm applications.
Add this crate to the dependencies section of your CosmWasm contract's Cargo.toml
file:
[dependencies]
pyth-sdk-cw = "1.0.0"
Simply import the structs exposed by the crate and use them while interacting with the pyth contract. For example:
// to query Pyth contract
use pyth_sdk_cw::{
PriceFeedResponse,
query_price_feed,
};
... {
let price_feed_response: PriceFeedResponse = query_price_feed(&deps.querier, state.pyth_contract_addr, state.price_feed_id)?;
let price_feed = price_feed_response.price_feed;
}
....
This snippet returns a PriceFeed
struct which exposes methods for reading the current price along with other useful functionality.
See the Pyth common SDK documentation for more information
about this struct.
The common SDK also provides methods for combining price feeds in several useful ways.
These methods allow you to derive prices for alternative quote currencies -- for example, to derive the BTC/ETH price from
the BTC/USD and ETH/USD price feeds -- and to price baskets of currencies.
Pyth is currently available on the following cosmwasm chains:
Network | Contract address |
---|---|
Injective | inj1z60tg0tekdzcasenhuuwq3htjcd5slmgf7gpez |
Available price feeds on these networks can be find below:
Network | Available Price Feeds |
---|---|
Injective Testnet | https://pyth.network/developers/price-feed-ids#injective-testnet |