Documentation
    Preparing search index...

    Interface ITonConnect

    Public contract of the TON Connect connector.

    interface ITonConnect {
        account: null | Account;
        connected: boolean;
        wallet: null | Wallet;
        connect<
            T extends
                | WalletConnectionSource
                | Pick<WalletConnectionSourceHTTP, "bridgeUrl">[],
        >(
            wallet: T,
            request?: ConnectAdditionalRequest,
            options?: OptionalTraceable<
                {
                    embeddedRequest?: ConsumableLike<EmbeddedRequest>;
                    linkDisplayOnly?: boolean;
                    openingDeadlineMS?: number;
                    signal?: AbortSignal;
                },
            >,
        ): T extends WalletConnectionSourceJS
            ? void
            : T extends WalletConnectionSourceWalletConnect ? void : string;
        disconnect(
            options?: OptionalTraceable<{ signal?: AbortSignal }>,
        ): Promise<void>;
        getSessionId(): Promise<null | string>;
        getWallets(): Promise<WalletInfo[]>;
        onStatusChange(
            callback: (walletInfo: null | Wallet) => void,
            errorsHandler?: (err: TonConnectError) => void,
        ): () => void;
        pauseConnection(): void;
        restoreConnection(
            options?: OptionalTraceable<
                { openingDeadlineMS?: number; signal?: AbortSignal },
            >,
        ): Promise<void>;
        sendTransaction(
            transaction: SendTransactionRequest,
            options?: OptionalTraceable<
                { onRequestSent?: () => void; signal?: AbortSignal },
            >,
        ): Promise<OptionalTraceable<SendTransactionResponse>>;
        sendTransaction(
            transaction: SendTransactionRequest,
            onRequestSent?: () => void,
        ): Promise<OptionalTraceable<SendTransactionResponse>>;
        setConnectionNetwork(network?: string): void;
        signData(
            data: SignDataPayload,
            options?: OptionalTraceable<
                { onRequestSent?: () => void; signal?: AbortSignal },
            >,
        ): Promise<OptionalTraceable<SignDataResponse>>;
        signMessage(
            message: SendTransactionRequest,
            options?: OptionalTraceable<
                { onRequestSent?: () => void; signal?: AbortSignal },
            >,
        ): Promise<OptionalTraceable<SignMessageResponse>>;
        unPauseConnection(): Promise<void>;
    }

    Implemented by

    Index

    Properties

    account: null | Account

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

    connected: boolean

    true while a wallet session is active. Equivalent to wallet !== null.

    wallet: null | Wallet

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

    Methods

    • End the session. Clears the local session state, fires the disconnected onStatusChange event immediately, and sends a disconnect RPC to the wallet so it can clean up its side too.

      Parameters

      Returns Promise<void>

      WalletNotConnectedError when no wallet is connected.

    • Current bridge session ID, or null if no session is open.

      Returns Promise<null | string>

    • Fetch the wallets-list registry, merged with any JS-injectable wallets detected on the page.

      Returns Promise<WalletInfo[]>

    • Subscribe to connection state changes. The callback fires after every connect, disconnect, restore. errorsHandler, when provided, is called with a TonConnectError subclass when the connector observes a connect failure (manifest fetch error, user rejection, wrong network, missing features).

      Parameters

      Returns () => void

      Unsubscribe function. Call it to stop receiving updates.

    • Pause the SSE bridge connection.

      Returns void

    • Try to restore the previous session from storage. Call this once on dApp startup, before deciding whether to show the connect modal.

      Resolves when the restore attempt has settled — either with a successful onStatusChange emission (session restored) or with the connector remaining disconnected (no session, or the wallet ended it).

      Parameters

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

      Returns Promise<void>

    • Constrain the network the connector will accept. Must be set before calling ITonConnect.connect — attempting to change it while a wallet is connected throws.

      If the wallet replies with a different chain id, the SDK aborts the connection and surfaces WalletWrongNetworkError to ITonConnect.onStatusChange's error handler.

      Pass undefined to clear the restriction and accept any network.

      Parameters

      • Optionalnetwork: string

        — desired network. See ChainId.

      Returns void

    • Resume a connection paused with ITonConnect.pauseConnection.

      Returns Promise<void>