Before installing and setting up the TON Pay SDK, the application must provide a TON Connect manifest, which is a JSON file that defines application metadata. Wallets use this manifest to discover the application.
# APInpm i @ton-pay/api# UI (install separately from API)npm i @ton-pay/ui-react @tonconnect/ui-react
# APInpm i @ton-pay/api# UI (install separately from API)npm i @ton-pay/ui @tonconnect/ui
2
Add TON Connect provider
TON Pay UI uses TON Connect UI for wallet communication.The application must be wrapped with TonConnectUIProvider and configured with an absolute URL to the TON Connect manifest. Add TonConnectUIProvider at the root of the application.
import { TonConnectUIProvider } from '@tonconnect/ui-react';import AppContent from "./AppContent";export default function App() { return ( <TonConnectUIProvider manifestUrl="https://myapp.com/tonconnect-manifest.json"> <AppContent /> </TonConnectUIProvider> );}
3
Add a payment button
Add a TonPayButton and provide a handler. The handler uses useTonPay to connect a wallet if needed, send a transaction through TON Connect, and track the transaction result.
TonPayButton wraps wallet connect and disconnect UX and invokes the provided handler.
useTonPay accepts an async message factory that receives senderAddr and returns { message } along with any tracking fields to propagate.
The returned { message } is a TON Connect transaction message. useTonPay forwards it to the wallet through TON Connect and initiates the transaction send; direct calls to the wallet SDK are not required.
// Backend: POST /api/create-paymentimport { createTonPayTransfer } from "@ton-pay/api";import { TON } from "@ton-pay/api";app.post("/api/create-payment", async (req, res) => { const { productId, senderAddr } = req.body; // Use the backend to create an order and calculate the amount using productId price const amount = 12.23; // order amount const orderId = 1; // ID of a new order // 1) Create transfer + get tracking identifiers const { message, reference, bodyBase64Hash } = await createTonPayTransfer( { amount, asset: TON, recipientAddr: "<WALLET_ADDRESS>", senderAddr }, { chain: "testnet", apiKey: "<TONPAY_API_KEY>" } // API key is optional ); // 2) Persist identifiers the DB (orderId, reference, bodyBase64Hash) immediately // 3) Return only the message to the client res.json({ message });});
This minimal example scaffolds a React app, installs TON Pay dependencies, and renders a working button wired to TON Connect. Replace the manifest URL and recipientAddr with the necessary values.
npx create-react-app my-app --template typescriptcd my-appnpm i @ton-pay/api @ton-pay/ui-react @tonconnect/ui-react