Skip to content

Commit 27c8fce

Browse files
authored
add ton send-usd example (#514)
1 parent 35a743d commit 27c8fce

File tree

1 file changed

+25
-1
lines changed
  • pages/price-feeds/use-real-time-data

1 file changed

+25
-1
lines changed

pages/price-feeds/use-real-time-data/ton.mdx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ Install the Pyth TON SDK and other necessary dependencies using npm:
2727
</Tabs.Tab>
2828
</Tabs>
2929

30+
## Write Contract Code
31+
32+
The code snippet below provides an example sending a message to the Pyth price feed contract and call the `parse_price_feed_updates` method:
33+
34+
```func copy
35+
;; Create message to Pyth contract according to schema
36+
cell msg = begin_cell()
37+
.store_uint(0x18, 6) ;; nobounce
38+
.store_slice(ctx_pyth_address) ;; pyth contract address
39+
.store_coins(forward_amount) ;; forward amount minus fees
40+
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1) ;; default message headers
41+
.store_uint(PYTH_OP_PARSE_PRICE_FEED_UPDATES, 32) ;; pyth opcode
42+
.store_ref(price_update_data) ;; update data
43+
.store_ref(price_ids) ;; price feed IDs
44+
.store_uint(now() - 100, 64) ;; min_publish_time
45+
.store_uint(now() + 100, 64) ;; max_publish_time
46+
.store_slice(my_address()) ;; target address (this contract)
47+
.store_ref(custom_payload) ;; custom payload with recipient and amount
48+
.end_cell();
49+
50+
send_raw_message(msg, 0);
51+
```
52+
3053
## Write Client Code
3154

3255
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
109132
- [Pyth Price Feed IDs](https://pyth.network/developers/price-feed-ids)
110133
- [Pyth TON Contract](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ton/contracts)
111134
- [Pyth TON SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ton/sdk)
112-
- [Pyth TON Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/sdk_js_usage)
135+
- [Pyth TON SDK Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/sdk_js_usage)
136+
- [Pyth TON Send USD Example](https://github.com/pyth-network/pyth-examples/tree/main/price_feeds/ton/send_usd)

0 commit comments

Comments
 (0)