Skip to content

Commit 2b1e05f

Browse files
committed
add send_usd example
1 parent 69fc257 commit 2b1e05f

16 files changed

+7272
-54
lines changed

.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=""

.gitignore

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,18 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
.idea
1+
node_modules
2+
temp
83
build
4+
dist
5+
.DS_Store
96

10-
# node-waf configuration
11-
.lock-wscript
12-
13-
# Compiled binary addons (https://nodejs.org/api/addons.html)
14-
build/Release
15-
16-
# Dependency directories
17-
node_modules/
18-
**/node_modules/
19-
jspm_packages/
20-
21-
# TypeScript v1 declaration files
22-
typings/
23-
24-
# Optional npm cache directory
25-
.npm
26-
27-
# Optional eslint cache
28-
.eslintcache
29-
30-
# Optional REPL history
31-
.node_repl_history
7+
# VS Code
8+
.vscode/*
9+
.history/
10+
*.vsix
3211

33-
# Output of 'npm pack'
34-
*.tgz
12+
# IDEA files
13+
.idea
3514

36-
# Yarn Integrity file
37-
.yarn-integrity
15+
# VIM
16+
Session.vim
3817

39-
# dotenv environment variables file
4018
.env
41-
42-
# parcel-bundler cache (https://parceljs.org/)
43-
.cache
44-
45-
# next.js build output
46-
.next
47-
48-
# nuxt.js build output
49-
.nuxt
50-
51-
# vuepress build output
52-
.vuepress/dist
53-
54-
# MacOS specific
55-
.DS_Store
56-
57-
# Cargo build output
58-
target/

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

.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+
}

README.md

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,83 @@
1-
# Pyth Examples
1+
# send_usd
22

3-
This repository contains examples of applications integrating Pyth products and services.
3+
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)