TonPayButton is a ready-to-use React component that handles wallet connection, payment flow, and provides a beautiful, customizable UI. Itβs the fastest way to integrate TON payments into your React application.
Installation
1
Install required packages
Install the React UI package along with TonConnect:
2
Create TonConnect manifest
Create a
tonconnect-manifest.json file in your public directory:Learn more about the manifest format in the TonConnect documentation.
3
Wrap your app with TonConnect provider
In your root component, wrap your app with
TonConnectUIProvider:Integration Guide
Choose one of two integration approaches based on your needs:Option 1: Using useTonPay Hook (Recommended)
TheuseTonPay hook simplifies wallet connection and transaction handling. Itβs the easiest way to integrate payments.
1
Import required dependencies
2
Set up the component
3
Create the payment handler
4
Render the button
For more details on using the
useTonPay hook, see the Send via useTonPay guide.Option 2: Using TonConnect Directly
For more control over the wallet connection flow, you can use TonConnectβs API directly.1
Import TonConnect hooks
2
Set up hooks and state
3
Create the payment handler
4
Render the button
For more details on using TonConnect directly, see the Send via TonConnect guide.
π API Reference
Props
All props are optional excepthandlePay.
| Prop | Type | Default | Description |
|---|---|---|---|
handlePay | () => Promise<void> | required | Payment handler function called when user clicks the button |
isLoading | boolean | false | Shows 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/textColor) |
onError | (error: unknown) => void | - | Called when handlePay throws. A built-in error popup is also shown by default unless showErrorNotification is false. |
showErrorNotification | boolean | true | Whether to show the built-in error notification popup when an error occurs |
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 | Show dropdown menu with wallet actions |
disabled | boolean | false | Disables the button |
style | Record<string, any> | - | Additional inline styles |
className | string | - | Additional CSS class name |
Features
Highly Customizable
Full control over colors, gradients, border radius, and fonts
Built-in Presets
Ready-to-use themes matching Figma designs
Wallet Integration
Connect, disconnect, and copy address via dropdown menu
Loading States
Built-in spinner and customizable loading text
Responsive Design
Flexible sizing with pixel or percentage values
Zero Config
Works out of the box with sensible defaults
Customization
Button Variants
The button comes in two text variants:Presets
Use built-in themes for quick styling:Custom Styling
Customize colors, sizes, and appearance:Button States
Control button behavior and appearance:Advanced Patterns
Error Handling
Always handle payment errors gracefully:Built-in error notification
TonPayButton automatically catches errors thrown from handlePay and shows a notification popup with the error message. This works out of the box - no configuration needed.
If you also render your own error UI (like the example above), users will see both messages. To avoid double messaging, either rely on the built-in popup or fully handle errors yourself as shown below.
Add a custom error handler
Use theonError prop to run side effects (analytics, logging, custom toasts). By default, the built-in popup will also appear. Set showErrorNotification={false} to disable it:
Replace the popup with your own UI
If you prefer to completely replace the built-in popup, catch errors insidehandlePay and do not rethrow. When handlePay resolves successfully (even after handling an error internally), the button will not show the default popup:
Server-Side Payment Creation
For better security and tracking, create payments on your backend:1
Create backend endpoint
Create an API endpoint that builds the payment message:
2
Call from frontend
Testing Your Integration
Run the interactive button showcase to test all variants and styling options:- Test different button variants and presets
- Try custom colors and sizes
- Verify loading and disabled states
- Interact with the dropdown menu
- See how the button behaves in different scenarios
Best Practices
1. Handle errors gracefully
1. Handle errors gracefully
Wrap payment calls in try-catch blocks and display user-friendly error messages. Network issues and user cancellations are common scenarios.
2. Show loading states
2. Show loading states
Always set
isLoading={true} during payment processing to prevent double submissions and provide visual feedback to users.3. Validate before payment
3. Validate before payment
Verify cart totals, user input, and business rules before calling the payment handler.
4. Test with testnet first
4. Test with testnet first
Use
chain: "testnet" during development. Only switch to "mainnet" after thorough testing.5. Store tracking identifiers
5. Store tracking identifiers
Always save
reference and bodyBase64Hash to track payment status via webhooks. See the Webhooks guide for details.6. Provide success feedback
6. Provide success feedback
After successful payment, show a confirmation message, redirect to a success page, or update your UI to reflect the completed transaction.