Installation
Choose an installation method
Choose one of the installation methods:
-
npm
-
CDN: no installation needed
-
Local copy
After npm install, copy
node_modules/@ton-pay/ui/dist/ton-pay-embed.jsto a public assets folder. For example, the site’spublic/directory. Then include it with a<script src="...">tag in HTML.
Create a TON Connect manifest
Create a Placeholders:
tonconnect-manifest.json file and host it on a public HTTPS URL.<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.
The
callback parameter in the embed script must match the global function name in the handler.Option 2: use TON Pay client
UsecreateTonPay for custom UI and payment flow control.
Create messages with createTonPayTransfer
UsecreateTonPayTransfer to build a canonical payment message with tracking identifiers.
Combine the snippets in this section into one HTML page.
Store
reference and bodyBase64Hash to track payment status via the webhooks guide.Embed script parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
containerId | string | "ton-pay-btn" | Target element ID where the button renders. |
preset | "default" | "gradient" | - | Built-in theme preset. |
bgColor | string | "#0098EA" | Background color in hex or CSS gradient. URL-encode the value. |
textColor | string | "#FFFFFF" | Text and icon color. |
variant | "long" | "short" | "long" | Button text variant. |
text | string | - | Custom button text. Overrides variant. |
loadingText | string | "Processing..." | Text shown during loading. |
borderRadius | number | 8 | Border radius in pixels. |
fontFamily | string | "inherit" | CSS font-family value. |
width | number | 300 | Button width in pixels. |
height | number | 44 | Button height in pixels. |
showMenu | boolean | true | Show dropdown menu with wallet actions. |
callback | string | - | Global function name called on click. |
Examples
URL-encode special characters in parameters. For example,
# becomes %23 in color values.TonPayEmbed API
The embed script exposes a globalTonPayEmbed 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 | nullCurrent 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
referenceandbodyBase64HashfromcreateTonPayTransferto track payments via webhooks. - Test with testnet first and handle error scenarios before going live.
Troubleshooting
If the button does not render
If the button does not render
If the callback is not invoked
If the callback is not invoked
- Ensure the callback function is defined on the
windowobject - Verify that the function name matches the
callbackparameter exactly - Define the callback before the embed script runs
If import map erros occur
If import map erros occur
- Add the import map before any module scripts
- Verify that the
@tonconnect/uiversion is compatible - Check that the import map syntax is valid
If CORS errors occur
If CORS errors occur
- Serve the manifest from the same domain or enable CORS
- Use HTTPS in production
- Verify that CDN resources are accessible