TonPayButton is a ready-to-use React component that handles wallet connection and payment flow with configurable styling for TON payments. The default button appearance is shown below.
Install packages
Create a TON Connect manifest
Create
tonconnect-manifest.json in the app public directory:Option 1: use useTonPay hook
TheuseTonPay hook simplifies wallet connection and transaction handling. Use it for a direct integration path.
Option 2: use TON Connect directly
Use TON Connect hooks directly when full control over the connection flow is required.TonPayButton props
All props are optional excepthandlePay.
| Prop | Type | Default | Description |
|---|---|---|---|
handlePay | () => Promise<void> | required | Payment handler called when the button is selected. |
isLoading | boolean | false | Shows a loading spinner and disables the button. |
variant | "long" | "short" | "long" | Button text variant: “Pay with TON Pay” (long) or “TON Pay” (short). |
preset | "default" | "gradient" | - | Predefined theme preset; overrides bgColor and textColor. |
onError | (error: unknown) => void | - | Called when handlePay throws. A built-in error popup is also shown unless showErrorNotification is false. |
showErrorNotification | boolean | true | Shows the built-in error notification popup on error. |
bgColor | string | "#0098EA" | Background color (hex) or CSS gradient. |
textColor | string | "#FFFFFF" | Text and icon color (hex). |
borderRadius | number | string | 8 | Border radius in pixels or CSS value. |
fontFamily | string | "inherit" | Font family for button text. |
width | number | string | 300 | Button width in pixels or CSS value. |
height | number | string | 44 | Button height in pixels or CSS value. |
loadingText | string | "Processing..." | Text shown during loading state. |
showMenu | boolean | true | Shows the dropdown menu with wallet actions. |
disabled | boolean | false | Disables the button. |
style | Record<string, any> | - | Additional inline styles. |
className | string | - | Additional CSS class name. |
Customization
Button variants
UseuseTonPay for a complete example.
Presets
UseuseTonPay for a complete example.
Custom styling
UseuseTonPay for a complete example.
bgColor. For example: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)".
Button states
UseuseTonPay for a complete example.
Advanced patterns
Error handling
Built-in error notification
TonPayButton catches errors thrown from handlePay and shows a notification pop-up with the error message.
If a custom error UI is also rendered, both messages appear. Use either the built-in pop-up or a custom UI, but not both.
Add a custom error handler
UseonError for logging or custom notifications. Set showErrorNotification={false} to disable the built-in pop-up.
handlePay and do not rethrow. When handlePay resolves, the button does not show the default pop-up.
Server-side payment creation
Create the payment message on a backend to store tracking identifiers and validate parameters before sending.Test the integration
Run the interactive button showcase to test variants and styling.Best practices
- Wrap payment calls in try-catch blocks and display user-friendly error messages. Network issues and cancellations are common.
- Set
isLoading={true}during payment processing to prevent double submissions and provide visual feedback. - Verify cart totals, user input, and business rules before calling the payment handler.
- Use
chain: "testnet"during development. Switch to"mainnet"only after validation. - Save
referenceandbodyBase64Hashto track payment status using webhooks. - After successful payment, show a confirmation message, redirect to a success page, or update the UI.