Skip to content

Commit 00a3e3d

Browse files
authored
feat: add send_usd example for ton (#37)
* add send_usd example for ton * update data * update readme * address comments
1 parent 69fc257 commit 00a3e3d

File tree

16 files changed

+7274
-0
lines changed

16 files changed

+7274
-0
lines changed

price_feeds/ton/send_usd/.env.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
WALLET_VERSION="v4"
2+
WALLET_MNEMONIC=""
3+
TONCENTER_API_KEY="" # Get from https://toncenter.com/
4+
PYTH_CONTRACT_ADDRESS="EQB4ZnrI5qsP_IUJgVJNwEGKLzZWsQOFhiaqDbD7pTt_f9oU"
5+
SEND_USD_CONTRACT_ADDRESS="EQBSXhaZHDbb7WRcdxXnmlFXsh_VDLJFSuFdWWV_FxxWFx-q"

price_feeds/ton/send_usd/.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
node_modules
2+
temp
3+
build
4+
dist
5+
.DS_Store
6+
7+
# VS Code
8+
.vscode/*
9+
.history/
10+
*.vsix
11+
12+
# IDEA files
13+
.idea
14+
15+
# VIM
16+
Session.vim
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

price_feeds/ton/send_usd/.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 4,
4+
"singleQuote": true,
5+
"bracketSpacing": true,
6+
"semi": true
7+
}

price_feeds/ton/send_usd/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# send_usd
2+
3+
This repository contains examples of applications integrating Pyth products and services. Sample contract demonstrating Pyth price feed integration on TON.
4+
5+
## Overview
6+
7+
This contract enables USD-denominated payments on TON by integrating with Pyth price oracles. It supports two operations:
8+
9+
1. `send_usd` - Send a USD-denominated payment that gets converted to TON at current price
10+
11+
Message format:
12+
13+
```typescript
14+
{
15+
queryId: number, // 64-bit unique identifier for the request
16+
recipient: Address, // TON address of payment recipient
17+
usdAmount: number, // Amount in USD dollars
18+
updateData: Buffer, // Pyth price update data (converted to cell chain)
19+
value: bigint // Amount of TON to attach to message
20+
}
21+
```
22+
23+
The `updateData` field contains Pyth price feed data and must be obtained from [Hermes](https://hermes.pyth.network/docs/). This data is converted to a TON cell chain format using the `createCellChain()` helper from the [pyth-ton-js](https://www.npmjs.com/package/@pythnetwork/pyth-ton-js) library. The Pyth contract can be found [here](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ton/contracts).
24+
25+
2. Pyth price update callback
26+
27+
- Receives price updates from Pyth oracle contract
28+
- Automatically processes pending USD payments using latest price
29+
30+
## Setup
31+
32+
1. Copy environment config:
33+
34+
```bash
35+
cp .env.example .env
36+
```
37+
38+
2. Configure `.env`:
39+
40+
```
41+
WALLET_MNEMONIC="your mnemonic here"
42+
```
43+
44+
## Usage
45+
46+
1. Deploy contract:
47+
48+
```bash
49+
npx blueprint run deploySendUsd --custom https://testnet.toncenter.com/api/v2/jsonRPC --custom-version v2 --custom-type testnet --custom-key <YOUR-API-KEY> --mnemonic
50+
```
51+
52+
This will deploy the contract and update `.env` with the deployed address.
53+
54+
2. Send USD payment:
55+
56+
```bash
57+
npx blueprint run sendUsdPayment <YOUR-TON-WALLET-ADDRESS> 1 --custom https://testnet.toncenter.com/api/v2/jsonRPC --custom-version v2 --custom-type testnet --custom-key <YOUR-API-KEY> --mnemonic
58+
```
59+
60+
## Project structure
61+
62+
- `contracts` - Smart contract source code and dependencies
63+
- `wrappers` - Contract wrapper classes implementing serialization and compilation
64+
- `tests` - Contract test suite
65+
- `scripts` - Deployment and interaction scripts
66+
67+
## Development
68+
69+
### Build
70+
71+
`npx blueprint build` or `yarn blueprint build`
72+
73+
### Test
74+
75+
`npx blueprint test` or `yarn blueprint test`
76+
77+
### Deploy or run scripts
78+
79+
`npx blueprint run` or `yarn blueprint run`
80+
81+
### Create new contract
82+
83+
`npx blueprint create ContractName` or `yarn blueprint create ContractName`

0 commit comments

Comments
 (0)