Skip to content

Commit 19fb611

Browse files
committed
added pyth docs
1 parent 24426fb commit 19fb611

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

docs/tools/oracles/pyth.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Pyth Network
2+
3+
[Pyth Network]: https://pyth.network/
4+
5+
## Overview
6+
7+
The [Pyth Network] is the **largest** first-party financial oracle network, delivering real-time market data to over 40 blockchains securely and transparently.
8+
9+
The network comprises some of the world’s largest exchanges, market makers, and financial services providers publishing their proprietary price data on-chain for aggregation and distribution to smart contract applications.
10+
11+
## Using Pyth Network
12+
13+
The Pyth Network introduced an innovative low-latency [pull oracle design](https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand), where users are empowered to “pull” price updates on-chain when needed, enabling everyone in that blockchain environment to access that data point.
14+
15+
Developers on Polygon have permissionless access to any of Pyth’s 350+ price feeds for equities, ETFs, commodities, foreign exchange pairs, and cryptocurrencies.
16+
17+
Here is a working example of a contract that fetches the latest price of MATIC/USD on the Polygon mainnet.
18+
You have to pass [Pyth's contract address](https://docs.pyth.network/price-feeds/contract-addresses/evm) of Polygon mainnet/mumbai and the desired [price feed](https://pyth.network/developers/price-feed-ids) id](https://pyth.network/developers/price-feed-ids) to fetch the latest price
19+
20+
```solidity
21+
// SPDX-License-Identifier: UNLICENSED
22+
pragma solidity ^0.8.13;
23+
24+
import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
25+
26+
contract MyFirstPythContract {
27+
IPyth pyth;
28+
29+
constructor(address _pyth) {
30+
pyth = IPyth(_pyth);
31+
}
32+
33+
function fetchPrice(
34+
bytes[] calldata pythPriceUpdate,
35+
bytes32 priceFeed
36+
) public payable returns (int64) {
37+
uint updateFee = pyth.getUpdateFee(pythPriceUpdate);
38+
pyth.updatePriceFeeds{value: updateFee}(pythPriceUpdate);
39+
40+
// Fetch the latest price
41+
PythStructs.Price memory price = pyth.getPrice(priceFeed);
42+
return price.price;
43+
}
44+
}
45+
46+
```
47+
48+
Here you can fetch the `updateData` from our [`Hermes`](https://docs.pyth.network/price-feeds/pythnet-price-feeds/hermes), which listens to Pythnet and Wormhole for price updates or you can use [`pyth-evm-js`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/sdk/js/src/EvmPriceServiceConnection.ts#L15) sdk.
49+
50+
51+
This [package](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ethereum/sdk/solidity) provides utilities for consuming prices from the Pyth Network Oracle using Solidity. Also, it contains the [Pyth Interface ABI](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/sdk/solidity/abis/IPyth.json) that you can use in your libraries to communicate with the Pyth contract.
52+
53+
It is strongly recommended to follow the consumer's [best practices](https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices) when consuming Pyth data.
54+
55+
For more information and details, please refer to the official documentation [here](https://docs.pyth.network/price-feeds).
56+
57+
You can find more details on the various functions available to you when interacting with the Pyth smart contract in the [API Reference section](https://docs.pyth.network/price-feeds/api-reference/evm).
58+
59+
## Pyth on Polygon
60+
61+
The Pyth Network smart contract is available at the following address:
62+
63+
- Mainnet: [0xff1a0f4744e8582DF1aE09D5611b887B6a12925C](https://polygonscan.com/address/0xff1a0f4744e8582df1ae09d5611b887b6a12925c).
64+
- Mumbai: [0xFC6bd9F9f0c6481c6Af3A7Eb46b296A5B85ed379](https://mumbai.polygonscan.com/address/0xFC6bd9F9f0c6481c6Af3A7Eb46b296A5B85ed379)
65+
66+
Additionally, you'll be able to find all the Pyth Price Feed IDs [here](https://pyth.network/developers/price-feed-ids). Be sure to select the correct environment as mainnet and testnet price feed IDs differ.
67+
68+
## Other
69+
70+
The Pyth Network provides additional tools to developers like this [TradingView Integration](https://docs.pyth.network/guides/how-to-create-tradingview-charts) or the [Gelato Web3 Functions](https://docs.pyth.network/guides/how-to-schedule-price-updates-with-gelato).
71+
72+
If you have any questions or issues, you can contact us on the following platforms: [Telegram](https://t.me/Pyth_Network), [Discord](https://discord.gg/invite/PythNetwork), [Website](https://pyth.network/contact).

0 commit comments

Comments
 (0)