Skip to content

feat: add ton send-usd example #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion pages/price-feeds/use-real-time-data/ton.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ Install the Pyth TON SDK and other necessary dependencies using npm:
</Tabs.Tab>
</Tabs>

## 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:
Expand Down Expand Up @@ -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)