diff --git a/pages/price-feeds/use-real-time-data/ton.mdx b/pages/price-feeds/use-real-time-data/ton.mdx index 2253ccbd..891e5e70 100644 --- a/pages/price-feeds/use-real-time-data/ton.mdx +++ b/pages/price-feeds/use-real-time-data/ton.mdx @@ -27,6 +27,29 @@ Install the Pyth TON SDK and other necessary dependencies using npm: +## Write Contract Code + +The code snippet below provides an example sending a message to the Pyth price feed contract and call the `parse_price_feed_updates` method: + +```func copy + ;; Create message to Pyth contract according to schema + cell msg = begin_cell() + .store_uint(0x18, 6) ;; nobounce + .store_slice(ctx_pyth_address) ;; pyth contract address + .store_coins(forward_amount) ;; forward amount minus fees + .store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1) ;; default message headers + .store_uint(PYTH_OP_PARSE_PRICE_FEED_UPDATES, 32) ;; pyth opcode + .store_ref(price_update_data) ;; update data + .store_ref(price_ids) ;; price feed IDs + .store_uint(now() - 100, 64) ;; min_publish_time + .store_uint(now() + 100, 64) ;; max_publish_time + .store_slice(my_address()) ;; target address (this contract) + .store_ref(custom_payload) ;; custom payload with recipient and amount + .end_cell(); + + send_raw_message(msg, 0); +``` + ## Write Client Code The following code snippet demonstrates how to fetch price updates, interact with the Pyth contract on TON, and update price feeds: @@ -109,4 +132,5 @@ You may find these additional resources helpful for developing your TON applicat - [Pyth Price Feed IDs](https://pyth.network/developers/price-feed-ids) - [Pyth TON Contract](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ton/contracts) - [Pyth TON SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ton/sdk) -- [Pyth TON Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/sdk_js_usage) +- [Pyth TON SDK Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/sdk_js_usage) +- [Pyth TON Send USD Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/send_usd)