| 
1 | 1 | # send_usd  | 
2 | 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 | + | 
3 | 60 | ## Project structure  | 
4 | 61 | 
 
  | 
5 |  | --   `contracts` - source code of all the smart contracts of the project and their dependencies.  | 
6 |  | --   `wrappers` - wrapper classes (implementing `Contract` from ton-core) for the contracts, including any [de]serialization primitives and compilation functions.  | 
7 |  | --   `tests` - tests for the contracts.  | 
8 |  | --   `scripts` - scripts used by the project, mainly the deployment scripts.  | 
 | 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  | 
9 | 66 | 
 
  | 
10 |  | -## How to use  | 
 | 67 | +## Development  | 
11 | 68 | 
 
  | 
12 | 69 | ### Build  | 
13 | 70 | 
 
  | 
 | 
17 | 74 | 
 
  | 
18 | 75 | `npx blueprint test` or `yarn blueprint test`  | 
19 | 76 | 
 
  | 
20 |  | -### Deploy or run another script  | 
 | 77 | +### Deploy or run scripts  | 
21 | 78 | 
 
  | 
22 | 79 | `npx blueprint run` or `yarn blueprint run`  | 
23 | 80 | 
 
  | 
24 |  | -### Add a new contract  | 
 | 81 | +### Create new contract  | 
25 | 82 | 
 
  | 
26 | 83 | `npx blueprint create ContractName` or `yarn blueprint create ContractName`  | 
0 commit comments