Installation
1
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.
2
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.
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
UsecreateTonPay 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
UsecreateTonPayTransfer 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 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 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