@tonconnect/ui-react reference
@tonconnect/ui-react is the React binding for @tonconnect/ui. It exposes a <TonConnectUIProvider> for app-wide setup, a <TonConnectButton> component, and hooks (useTonConnectUI, useTonAddress, useTonWallet) so React dApps can integrate TON Connect without touching the imperative UI API.
If your app does not use React, use @tonconnect/ui directly. For server-side use, see @tonconnect/sdk.
Installation
Install from npm:
npm i @tonconnect/ui-react@tonconnect/ui-react is a client-only package — under Next.js, mark the wrapping component with "use client" or import the provider with dynamic(..., { ssr: false }).
Generated from
@tonconnect/ui-reactv3.0.0-beta.2.
Types
TonConnectButtonProps
Props for TonConnectButton.
interface TonConnectButtonProps {
className?: string;
style?: CSSProperties;
}| Field | Type | Description |
|---|---|---|
className | string | Optional. Extra class name applied to the button container. |
style | CSSProperties | Optional. Inline styles merged with the button container's width: fit-content default. |
TonConnectUIProviderPropsWithManifest
Pass a manifestUrl and let the provider build a TonConnectUI from
the merged UI options.
interface TonConnectUIProviderPropsWithManifest {
manifestUrl: string;
}| Field | Type | Description |
|---|---|---|
manifestUrl | string | HTTPS URL of the dApp's tonconnect-manifest.json. The provider builds the TonConnectUI connector from it. |
TonConnectUIProviderPropsWithConnector
Pass a pre-built ITonConnect (typically from @tonconnect/sdk) — the
provider wraps it in a TonConnectUI. Useful when the dApp drives the
underlying SDK directly and only wants the React UI on top.
interface TonConnectUIProviderPropsWithConnector {
connector: ITonConnect;
}| Field | Type | Description |
|---|---|---|
connector | ITonConnect | Existing ITonConnect instance. The provider will not create its own. |
TonConnectUIProviderPropsBase
Common UI options accepted in addition to the constructor selector
(manifestUrl / connector). All optional; mirror the fields on
TonConnectUiOptions from @tonconnect/ui.
interface TonConnectUIProviderPropsBase {
restoreConnection: boolean;
language: Locales;
widgetRootId: string;
uiPreferences?: UIPreferences;
walletsListConfiguration?: WalletsListConfiguration;
walletsRequiredFeatures?: RequiredFeatures;
walletsPreferredFeatures?: RequiredFeatures;
actionsConfiguration?: ActionConfiguration;
enableAndroidBackHandler?: boolean;
analytics?: AnalyticsSettings;
}| Field | Type | Description |
|---|---|---|
restoreConnection | boolean | Attempt to restore the previous session from storage on mount. Set to false for flows that prefer an explicit connect step. Defaults to true. |
language | Locales | Language for SDK-rendered strings. Defaults to 'en'. |
widgetRootId | string | HTML element ID under which the modal root is attached. Defaults to tc-widget-root (created at the end of <body>). |
uiPreferences | UIPreferences | Optional. Visual configuration — theme, border radius, color overrides. |
walletsListConfiguration | WalletsListConfiguration | Optional. Wallets-list overrides — include extra wallets, reorder existing ones. |
walletsRequiredFeatures | RequiredFeatures | Optional. Hide wallets from the picker that don't advertise the listed features. Non-matching entries are greyed out below the separator and rejected at connect time with WalletMissingRequiredFeaturesError. |
walletsPreferredFeatures | RequiredFeatures | Optional. Soft preference filter — non-matching wallets remain clickable but sorted below the separator. The SDK does NOT enforce the match at connect time. |
actionsConfiguration | ActionConfiguration | Optional. Modal / notification behavior and the return strategy for action deep links. See ActionConfiguration. |
enableAndroidBackHandler | boolean | Optional. Close modals and notifications when the Android back button is pressed. Disable when the dApp manages browser history manually. Defaults to true. |
analytics | AnalyticsSettings | Optional. Analytics configuration forwarded to the underlying TonConnect instance. See AnalyticsSettings from @tonconnect/sdk. |
TonConnectUIProviderProps
Props for <TonConnectUIProvider>. Pick one of three shapes:
TonConnectUIProviderPropsWithManifest— most common: pass amanifestUrl, the provider builds aTonConnectUIfor you.TonConnectUIProviderPropsWithConnector— pass a pre-builtITonConnect(from@tonconnect/sdk); the provider wraps it in UI.TonConnectUIProviderPropsWithInstance— pass an externally constructedTonConnectUI.
The manifest / connector variants accept the same UI-level options as the
vanilla TonConnectUiOptions (theme, language, wallet filters,
analytics).
type TonConnectUIProviderProps =
& { children: ReactNode }
& (Partial<TonConnectUIProviderPropsBase & (TonConnectUIProviderPropsWithManifest | TonConnectUIProviderPropsWithConnector)> | TonConnectUIProviderPropsWithInstance);Components
TonConnectButton()
function TonConnectButton(props: TonConnectButtonProps): ReactNode;| Parameter | Type | Description |
|---|---|---|
props | TonConnectButtonProps | — |
Returns ReactNode.
TonConnectUIProvider()
function TonConnectUIProvider(props: TonConnectUIProviderProps): ReactNode;| Parameter | Type | Description |
|---|---|---|
props | TonConnectUIProviderProps | — |
Returns ReactNode.
Hooks
useIsConnectionRestored()
Indicates current status of the connection restoring process.
function useIsConnectionRestored(): boolean;Returns boolean.
useTonAddress()
Reactive accessor for the connected account's TON address. Returns an empty string while disconnected.
function useTonAddress(userFriendly: boolean = true): string;| Parameter | Type | Description |
|---|---|---|
userFriendly | boolean | Optional. — true (default) returns the non-bounceable base64url user-friendly form (UQ… on mainnet, 0Q… on testnet). Pass false to get the raw <workchain>:<hex> form. Defaults to true. |
Returns string.
Example:
const address = useTonAddress(); // user-friendly
const rawAddress = useTonAddress(false);useTonConnectModal()
Reactive wrapper around tonConnectUI.modal. Returns { state, open, close } — state mirrors WalletsModalState and re-renders on every
modal lifecycle event; open / close are convenience bindings.
Must be called inside a <TonConnectUIProvider>. Use this hook when the
dApp wants its own "Connect" UI separate from <TonConnectButton />.
function useTonConnectModal(): Omit<WalletsModal, 'onStateChange'>;Returns Omit<WalletsModal, 'onStateChange'>.
Example:
const { state, open, close } = useTonConnectModal();
return (
<>
<div>Modal status: {state?.status}</div>
<button onClick={open}>Open modal</button>
<button onClick={close}>Close modal</button>
</>
);useTonConnectUI()
Returns a tuple of:
- the singleton
TonConnectUIinstance — call every method (connectWallet,sendTransaction,signData,signMessage, modal helpers) on it; - a
setOptions(options)callback that merges the partialTonConnectUiOptionsinto the live instance via itsuiOptionssetter, triggering an immediate re-render.
Must be called inside a <TonConnectUIProvider>. On the server side,
the hook returns a no-op pair — call sites can render shells
without crashing, but the real wiring only kicks in once the component
hydrates in the browser.
function useTonConnectUI(): [TonConnectUI, (options: TonConnectUiOptions) => void];Returns [TonConnectUI, (options: TonConnectUiOptions) => void].
Example:
const [tonConnectUI, setOptions] = useTonConnectUI();
await tonConnectUI.sendTransaction(tx, { traceId });
setOptions({ language: 'ru' });useTonWallet()
Reactive accessor for the currently connected wallet. Returns null
while disconnected and refreshes on every onStatusChange event.
The shape mirrors tonConnectUI.wallet — Wallet (from @tonconnect/sdk)
merged with the picker entry for the wallet (icon, name, open method).
Must be called inside a <TonConnectUIProvider>.
function useTonWallet(): Wallet | Wallet & WalletInfoWithOpenMethod | null;Returns Wallet | Wallet & WalletInfoWithOpenMethod | null.
Example:
const wallet = useTonWallet();
if (!wallet) return <ConnectButton />;
return <span>{wallet.device.appName} · {wallet.account.address}</span>;Errors
Every error from this package extends TonConnectUIReactError, which itself extends TonConnectUIError. Use err instanceof TonConnectUIReactError to catch errors from this package; use err instanceof TonConnectUIError to catch anything raised by the TonConnect stack.
TonConnectUIReactError
Base class for every error thrown by @tonconnect/ui-react. Extends
TonConnectUIError from @tonconnect/ui, which itself extends
TonConnectError from @tonconnect/sdk — a single
catch (e instanceof TonConnectError) branch covers them all.
class TonConnectUIReactError extends TonConnectUIError {
constructor(message?: string, options?: ErrorOptions);
}Error catalogue
| Class | Thrown when |
|---|---|
TonConnectProviderNotSetError | Thrown when a hook from @tonconnect/ui-react (or <TonConnectButton />) is used outside the subtree rendered by <TonConnectUIProvider>. Add the provider near the top of your React tree. |
Related pages
@tonconnect/ui— framework-agnostic UI wrapped by these bindings.@tonconnect/sdk— connector core under the UI.@tonconnect/protocol— wire-format types.- TON Connect spec — normative protocol material.