|
| 1 | +## Overview |
| 2 | + |
| 3 | +The [Pyth network](https://pyth.network/) is the largest first-party financial oracle network, delivering real-time market data to over 40 blockchains securely and transparently. |
| 4 | + |
| 5 | +The network comprises some of the world’s largest exchanges, market makers, and financial services providers; publishing proprietary price-data on-chain for aggregation and distribution to smart contract applications. |
| 6 | + |
| 7 | +## Using Pyth network |
| 8 | + |
| 9 | +The Pyth network introduces an innovative low-latency [pull oracle design](https://docs.pyth.network/documentation/pythnet-price-feeds/on-demand), where users can pull price updates on-chain when needed, enabling everyone in the blockchain environment to access that data point. |
| 10 | + |
| 11 | +Developers on Polygon have permissionless access to any of Pyth’s 350+ price feeds for equities, ETFs, commodities, foreign exchange pairs, and cryptocurrencies. |
| 12 | + |
| 13 | +Here is a working example of a contract that fetches the latest price of MATIC/USD on the Polygon network. |
| 14 | +You have to pass [Pyth's contract address](https://docs.pyth.network/price-feeds/contract-addresses/evm) for Polygon mainnet/testnet and the desired [price feed id](https://pyth.network/developers/price-feed-ids) to fetch the latest price. |
| 15 | + |
| 16 | +```solidity |
| 17 | +// SPDX-License-Identifier: UNLICENSED |
| 18 | +pragma solidity ^0.8.13; |
| 19 | +
|
| 20 | +import "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; |
| 21 | +
|
| 22 | +contract MyFirstPythContract { |
| 23 | + IPyth pyth; |
| 24 | +
|
| 25 | + constructor(address _pyth) { |
| 26 | + pyth = IPyth(_pyth); |
| 27 | + } |
| 28 | +
|
| 29 | + function fetchPrice( |
| 30 | + bytes[] calldata pythPriceUpdate, |
| 31 | + bytes32 priceFeed |
| 32 | + ) public payable returns (int64) { |
| 33 | + uint updateFee = pyth.getUpdateFee(pythPriceUpdate); |
| 34 | + pyth.updatePriceFeeds{value: updateFee}(pythPriceUpdate); |
| 35 | +
|
| 36 | + // Fetch the latest price |
| 37 | + PythStructs.Price memory price = pyth.getPrice(priceFeed); |
| 38 | + return price.price; |
| 39 | + } |
| 40 | +} |
| 41 | +
|
| 42 | +``` |
| 43 | + |
| 44 | +Here you can fetch the `updateData` from our [`Hermes` feed](https://docs.pyth.network/price-feeds/pythnet-price-feeds/hermes), which listens to Pythnet and Wormhole for price updates; or you can use the [`pyth-evm-js`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/sdk/js/src/EvmPriceServiceConnection.ts#L15) SDK. |
| 45 | + |
| 46 | + |
| 47 | +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. |
| 48 | + |
| 49 | +We recommend following the [consumer best practices](https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices) when consuming Pyth data. |
| 50 | + |
| 51 | +For more information, check out the official [Pyth documentation](https://docs.pyth.network/price-feeds). There are details on the various functions available for interacting with the Pyth smart contract in the [API Reference section](https://docs.pyth.network/price-feeds/api-reference/evm). |
| 52 | + |
| 53 | +## Pyth on Polygon |
| 54 | + |
| 55 | +The Pyth Network smart contract is available at the following address: |
| 56 | + |
| 57 | +- Mainnet: [0xff1a0f4744e8582DF1aE09D5611b887B6a12925C](https://polygonscan.com/address/0xff1a0f4744e8582df1ae09d5611b887b6a12925c). |
| 58 | +- Amoy: [0x2880aB155794e7179c9eE2e38200202908C17B43](https://www.oklink.com/amoy/address/0x2880ab155794e7179c9ee2e38200202908c17b43) |
| 59 | + |
| 60 | +Additionally, click to access the [Pyth price-feed IDs](https://pyth.network/developers/price-feed-ids). |
| 61 | + |
| 62 | +## Developers and community |
| 63 | + |
| 64 | +The Pyth network provides additional tools to developers, such as [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). |
| 65 | + |
| 66 | +If you have any questions or issues, contact us on the following platforms: |
| 67 | + |
| 68 | +- [Telegram](https://t.me/Pyth_Network) |
| 69 | +- [Discord](https://discord.gg/invite/PythNetwork) |
| 70 | +- [Website](https://pyth.network/contact) |
0 commit comments