Documentation
    Preparing search index...

    Class TonConnect

    Headless TON Connect connector — implements the ITonConnect contract. Wraps the protocol handshake and the HTTP / JS bridge / WalletConnect transports.

    import TonConnect from '@tonconnect/sdk';

    const connector = new TonConnect({
    manifestUrl: 'https://example.com/tonconnect-manifest.json',
    });

    Implements

    Index

    Constructors

    • Create a new connector. See TonConnectOptions for every option; the most common shape is { manifestUrl } in the browser, and { manifestUrl, storage } in Node.js / non-browser hosts.

      Parameters

      Returns TonConnect

      DappMetadataError when manifestUrl is omitted and window.location.origin is not available.

    Properties

    isInsideWalletBrowser: (walletJSKey: string) => boolean

    true when the dApp is running inside the named wallet's in-app browser. Use it to pick the JS-bridge transport automatically and skip the QR-code modal.

    Type declaration

      • (walletJSKey: string): boolean
      • Parameters

        • walletJSKey: string

          — value of the wallet's jsBridgeKey in the wallets list.

        Returns boolean

    isWalletInjected: (walletJSKey: string) => boolean

    true when a wallet identified by walletJSKey exposes a JS bridge on the current page. The fastest way to detect a browser extension before deciding which connect source to build.

    Type declaration

      • (walletJSKey: string): boolean
      • Parameters

        • walletJSKey: string

          — value of the wallet's jsBridgeKey in the wallets list.

        Returns boolean

    Accessors

    • get account(): null | Account

      Current connected account or null if no account is connected.

      Returns null | Account

    • get connected(): boolean

      Shows if the wallet is connected right now.

      Returns boolean

    • get wallet(): null | Wallet

      Current connected wallet or null if no account is connected.

      Returns null | Wallet

    • set wallet(value: null | Wallet): void

      Currently connected Wallet, or null when no wallet is connected.

      Parameters

      Returns void

    Methods

    • Disconnect from the connected wallet and drop current session.

      Parameters

      Returns Promise<void>

    • Gets the current session ID if available.

      Returns Promise<null | string>

      session ID string or null if not available.

    • Allows to subscribe to connection status changes and handle connection errors.

      Parameters

      • callback: (wallet: null | Wallet) => void

        will be called after connections status changes with actual wallet or null.

      • OptionalerrorsHandler: (err: TonConnectError) => void

        (optional) will be called with some instance of TonConnectError when connect error is received.

      Returns () => void

      unsubscribe callback.

    • Pause bridge HTTP connection. Might be helpful, if you want to pause connections while browser tab is unfocused, or if you use SDK with NodeJS and want to save server resources.

      Returns void

    • Try to restore existing session and reconnect to the corresponding wallet. Call it immediately when your app is loaded.

      Parameters

      • Optionaloptions: OptionalTraceable<{ openingDeadlineMS?: number; signal?: AbortSignal }>

      Returns Promise<void>

    • Set desired network for the connection. Can only be set before connecting. If wallet connects with a different chain, the SDK will throw an error and abort connection.

      Parameters

      • Optionalnetwork: string

        desired network id (e.g., '-239', '-3', or custom). Pass undefined to allow any network.

      Returns void

    • Unpause bridge HTTP connection if it is paused.

      Returns Promise<void>

    • Fetch the wallets-list registry without instantiating a connector. Equivalent to ITonConnect.getWallets but usable before constructing a TonConnect.

      Returns Promise<WalletInfo[]>