Example:
- Price Feeds: Real-time pricing for cryptocurrencies, stocks, or commodities.
- Event Information: Updates on real-world events like sports results or weather conditions.
- API Access: Connections to external web services and systems.
Oracles, being external third-party services, require careful consideration of their reliability, security, and decentralization to avoid risks such as incorrect data, manipulation, or single points of failure.
Deployed Oracles on NEAR
Here is a directory of third-party oracle services deployed on the NEAR blockchain:| Name | Creator | Description |
|---|---|---|
| Price Oracle | NearDefi | Open source oracle for real-time asset pricing |
| Pyth Network Oracle | Pyth Network | High-frequency, low-latency oracle for price feeds |
| [Your Project Here] | - | - |
Price Oracle by NearDefi
- Creator: NearDefi
- Codebase Repository: NearDefi/price-oracle
- Bot for Data Feeds: NearDefi/near-price-oracle-bot
- Deployed Addresses:
- Mainnet: priceoracle.near
- Testnet: priceoracle.testnet
Query Assets
- 🖥️ CLI
Lantstool
Example Response
Example Response
Get Assets Price
- 🖥️ CLI
Lantstool
Example response
Example response
Pyth Network Oracle
- Creator: Pyth Network
- Official Documentation: Pyth NEAR Docs
- Codebase Repository: pyth-network/pyth-crosschain
- Deployed Addresses:
- Mainnet: pyth-oracle.near
- Testnet: pyth-oracle.testnet
Using Pyth Network Oracle
Pyth Network’s NEAR smart contract has two core methods to update & get price feeds of your choice.
update_price_feeds(updates Pyth smart contract with the price feed you provide)- args:
data - type:
object - example:
{ "data": "504e41...' }
- args:
get_price(fetches the most recent price stored in the contract)_- args:
price_identifier - type:
object - example:
{ price_identifier: 'f9c0172ba10dfa8...' }
- args:
For a complete list of endpoints to interact with, see Pyth’s
receiver contract.Getting Started
To get started with Pyth oracle you will need to gather the following information which differ between networks:- Price ID(s)
- HermesAPI Endpoint
- Smart contract address
| Network | Price Feed IDs | Hermes API Address | Contract Address |
|---|---|---|---|
testnet | NEAR testnet Price Feed IDs | hermes-beta.pyth.network | pyth-oracle.testnet |
mainnet | NEAR mainnet Price Feed IDs | hermes.pyth.network | pyth-oracle.near |
When using Price Feed IDs, you will need to remove the
0x prefix.Price Feed ID Example (testnet):update_price_feeds
Updates the Pyth Oracle contract data with the price feed you provide.
- args:
data(off-chain hex-encoded price feed) - type:
object - example:
{ "data": "504e41...' }
1) Fetching off-chain price feed
You can obtain an off-chain price feed using Pyth’s Hermes API. To use these endpoints, you will need to provide a Price Feed ID and ensure you are targeting the correct network. See Getting Started for more information. Here is a node.js example of fetching the latest price feed using/v2/updates/price/latest endpoint:
2) Update Pyth Oracle Contract Price Feed
After fetching an off-chain price feed, you can now perform a contract call to the Pyth Oracle to update the price feed on-chain. Callupdate_price_feeds on the Pyth Oracle contract with data as your arguments.
example args:
near-js/client and node.js:
Although unused deposit will be refunded, you can calculate an estimate by calling the
get_update_fee_estimate method against the Pyth contract.get_price
Fetches the most recent price feed stored in the Pyth Oracle contract. Is a view method, so does not require a signature or payment.
- args:
price_identifier(unique price feed identifier) - type:
object - example:
{ price_identifier: 'f9c0172ba10dfa8...' }
get_price on the Pyth Oracle contract. Note that this is a view method and does not require a signature or deposit.
Example: