Skip to main content
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

1

Install necessary libraries

2

Create a TON Connect manifest

Create tonconnect-manifest.json in the app public directory:
3

Wrap the app with the provider

Wrap the root component with TonConnectUIProvider.

Option 1: use useTonPay hook

The useTonPay hook simplifies wallet connection and transaction handling. Use it for a direct integration path.
1

Import required dependencies

2

Set up the component

3

Create the payment handler

4

Render the button

Option 2: use TON Connect directly

Use TON Connect hooks directly when full control over the connection flow is required.
1

Import TON Connect hooks

2

Set up hooks and state

3

Create the payment handler

4

Render the button

TonPayButton props

All props are optional except handlePay.

Customization

Button variants

Use useTonPay for a complete example.

Presets

Use useTonPay for a complete example.

Custom styling

Use useTonPay for a complete example.
CSS gradients can be used in bgColor. For example: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)".

Button states

Use useTonPay 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

Use onError for logging or custom notifications. Set showErrorNotification={false} to disable the built-in pop-up.
Replace the pop-up with a custom UI. Catch errors inside 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.
1

Create a backend endpoint

Build an endpoint that returns the message for TonPayButton.
2

Call the endpoint from the frontend

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 reference and bodyBase64Hash to track payment status using webhooks.
  • After successful payment, show a confirmation message, redirect to a success page, or update the UI.