Skip to main content
Add a TON Pay button to a plain HTML/JavaScript page using the embed script or TON Pay client. The default button appearance is shown below.

Installation

1

Choose an installation method

Choose one of the installation methods:
  1. npm
  2. CDN: no installation needed
  3. Local copy After npm install, copy node_modules/@ton-pay/ui/dist/ton-pay-embed.js to a public assets folder. For example, the site’s public/ directory. Then include it with a <script src="..."> tag in HTML.
2

Create a TON Connect manifest

Create a tonconnect-manifest.json file and host it on a public HTTPS URL.
Placeholders:
  • <APP_URL> – public HTTPS URL of the app.
  • <APP_NAME> – display name shown in the wallet.
  • <APP_ICON_URL> – public HTTPS URL of the app icon.

Option 1: embed script

Placeholders:
  • <CONTAINER_ID> – HTML element ID where the button is mounted.
  • <CALLBACK_NAME> – global function name invoked by the embed script.
  • <RECIPIENT_ADDR> – recipient wallet address.
1

Add the container

2

Add the embed script

3

Add the import map

4

Create the payment handler

Option 2: use TON Pay client

Use createTonPay for custom UI and payment flow control.
1

Set up the HTML

2

Import the TON Pay client and create an instance

3

Implement the payment logic

Create messages with createTonPayTransfer

Use createTonPayTransfer to build a canonical payment message with tracking identifiers. Combine the snippets in this section into one HTML page.
1

Add the API package script

2

Use the API in the payment handler

Embed script parameters

Examples

TonPayEmbed API

The embed script exposes a global TonPayEmbed object for programmatic control.

TonPayEmbed.mount(config)

Update button configuration dynamically.

TonPayEmbed.setCallback(functionName)

Change the callback function.

TonPayEmbed.setAddress(address)

Update the displayed wallet address in the menu.

TonPayEmbed.click()

Trigger a button click programmatically.

Example: dynamic configuration

TonPay client API

createTonPay returns a client for wallet connection and payments.

Properties

  • address: string | null Current wallet address.

Methods

  • waitForWalletConnection(): Promise<string> Wait for a wallet connection and open the modal if needed.
  • pay(getMessage): Promise<PayResult> Execute a payment transaction.
  • disconnect(): Promise<void> Disconnect the current wallet.

Framework integration

WordPress

Plain HTML/CSS/JS

Use the complete example of the embed script in a single HTML file.

Build tools: Webpack and Vite

Best practices

  • Wrap payment calls in try-catch blocks and display clear error messages.
  • Update the UI during payment processing to prevent repeated clicks.
  • Check amounts, addresses, and input before calling the payment function.
  • Use HTTPS in production. TON Connect requires HTTPS for the manifest URL and callbacks.
  • Save reference and bodyBase64Hash from createTonPayTransfer to track payments via webhooks.
  • Test with testnet first and handle error scenarios before going live.

Troubleshooting

  1. Verify that containerId matches the target div ID
  2. Check the browser console for errors
  3. Ensure the script loads after the container div
  4. Verify that the script URL is correct and accessible
  1. Ensure the callback function is defined on the window object
  2. Verify that the function name matches the callback parameter exactly
  3. Define the callback before the embed script runs
  1. Add the import map before any module scripts
  2. Verify that the @tonconnect/ui version is compatible
  3. Check that the import map syntax is valid
  1. Serve the manifest from the same domain or enable CORS
  2. Use HTTPS in production
  3. Verify that CDN resources are accessible