Skip to main content

generateTonConnectProof

Generates a TonConnect proof for authentication with backend services. This creates a cryptographic proof that the user owns the wallet.

Usage

import { generateTonConnectProof, isTonWalletAccount } from "@dynamic-labs-sdk/ton";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isTonWalletAccount(walletAccount)) {
  const proof = await generateTonConnectProof({
    payload: "authentication-challenge-from-backend",
    walletAccount,
  });

  console.log("TON Connect Proof:", proof);
  // {
  //   address: "UQ...",
  //   domain: { lengthBytes: 11, value: "example.com" },
  //   timestamp: 1704067200,
  //   payload: "authentication-challenge-from-backend",
  //   signature: "base64-encoded-signature"
  // }

  // Send this proof to your backend for verification
}

Parameters

ParameterTypeDescription
payloadstringThe proof payload, typically a nonce or challenge from your backend
walletAccountTonWalletAccountThe wallet account to generate the proof for
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

Promise<TonConnectProof> - A promise that resolves to the proof object:
FieldTypeDescription
addressstringWallet address
domainTonConnectDomainDomain information (see below)
payloadstringThe payload string that was signed
signaturestringSignature as a base64 string
timestampnumberUnix timestamp in seconds

TonConnectDomain

FieldTypeDescription
lengthBytesnumberLength of domain value in bytes
valuestringDomain value (e.g., “example.com”)

Errors

ErrorDescription
NotTonProviderErrorThrown if the wallet account’s provider is not a TON provider
MethodNotImplementedErrorThrown if the wallet provider does not support proof generation