Skip to main content

How to use real-time data in TON contracts

Pyth is a pull oracle. Pyth price feeds on TON are managed through the main TON Pyth smart contract, enabling seamless interaction with on-chain data. In TON, these interactions are facilitated by specific functions within the Pyth TON contract. This contract acts as an interface to Pyth price feeds, handling the retrieval and updating of price data.

Install the Pyth SDK

Install the Pyth TON SDK and other necessary dependencies using npm or yarn:

Write code to interact with oracle

Off-chain data fetch and update

The following code snippet demonstrates how to fetch price updates, interact with the Pyth contract on TON, and update price feeds: The following example uses the testnet contract. For mainnet usage, change the PYTH_CONTRACT_ADDRESS_TESTNET to PYTH_CONTRACT_ADDRESS_MAINNET accordingly.

Additional resources

You may find these additional resources helpful for developing your TON application: