WDK logoWDK documentation

API Reference

Complete API documentation for @tetherto/wdk-wallet-ton-gasless

Table of Contents

ClassDescriptionMethods
WalletManagerTonGaslessMain class for managing gasless TON walletsConstructor, Methods
WalletAccountTonGaslessIndividual gasless TON wallet account implementationConstructor, Methods
WalletAccountReadOnlyTonGaslessRead-only gasless TON wallet accountConstructor, Methods

WalletManagerTonGasless

The main class for managing gasless TON wallets. Extends WalletManager from @tetherto/wdk-wallet.

Constructor

new WalletManagerTonGasless(seed, config)

Parameters:

  • seed (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
  • config (TonGaslessWalletConfig): Configuration object
    • tonClient (object | TonClient): TON client configuration or instance
    • tonApiClient (object | TonApiClient): TON API client configuration or instance
      • url (string): TON API URL (e.g., 'https://tonapi.io/v2')
      • secretKey (string, optional): API key for TON API
    • paymasterToken (object): Paymaster token configuration
      • address (string): Paymaster token contract address
    • transferMaxFee (number, optional): Maximum fee for transfer operations

Example:

const wallet = new WalletManagerTonGasless(seedPhrase, {
  tonClient: {
    url: 'https://toncenter.com/api/v3',
    secretKey: 'your-api-key'
  },
  tonApiClient: {
    url: 'https://tonapi.io/v2',
    secretKey: 'your-tonapi-key'
  },
  paymasterToken: {
    address: 'EQ...'
  },
  transferMaxFee: 1000000000
})

Methods

MethodDescriptionReturns
getAccount(index)Returns a gasless wallet account at the specified indexPromise<WalletAccountTonGasless>
getAccountByPath(path)Returns a gasless wallet account at the specified BIP-44 derivation pathPromise<WalletAccountTonGasless>
getFeeRates()Returns current fee rates for transactionsPromise<{normal: number, fast: number}>
dispose()Disposes all wallet accounts, clearing private keys from memoryvoid
getAccount(index)

Returns a gasless wallet account at the specified index.

Parameters:

  • index (number, optional): The index of the account to get (default: 0)

Returns: Promise<WalletAccountTonGasless> - The wallet account

Example:

const account = await wallet.getAccount(0)
getAccountByPath(path)

Returns a gasless wallet account at the specified BIP-44 derivation path.

Parameters:

  • path (string): The derivation path (e.g., "0'/0/0")

Returns: Promise<WalletAccountTonGasless> - The wallet account

Example:

const account = await wallet.getAccountByPath("0'/0/1")
getFeeRates()

Returns current fee rates for transactions based on blockchain config.

Returns: Promise<{normal: number, fast: number}> - Object containing fee rates

Example:

const feeRates = await wallet.getFeeRates()
console.log('Normal fee rate:', feeRates.normal)
console.log('Fast fee rate:', feeRates.fast)
dispose()

Disposes all wallet accounts, clearing private keys from memory.

Example:

wallet.dispose()

WalletAccountTonGasless

Individual gasless TON wallet account implementation. Extends WalletAccountReadOnlyTonGasless and implements IWalletAccount.

Constructor

new WalletAccountTonGasless(seed, path, config)

Parameters:

  • seed (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
  • path (string): BIP-44 derivation path (e.g., "0'/0/0")
  • config (TonGaslessWalletConfig): Configuration object (same as WalletManagerTonGasless)

Methods

MethodDescriptionReturns
getAddress()Returns the account's TON addressPromise<string>
sign(message)Signs a message using the account's private keyPromise<string>
verify(message, signature)Verifies a message signaturePromise<boolean>
transfer(options, config?)Transfers tokens using gasless transactionsPromise<{hash: string, fee: number}>
quoteTransfer(options, config?)Estimates the fee for a token transferPromise<{fee: number}>
getBalance()Returns the native TON balance (in nanotons)Promise<bigint>
getTokenBalance(tokenAddress)Returns the balance of a specific tokenPromise<bigint>
getPaymasterTokenBalance()Returns the balance of the paymaster tokenPromise<bigint>
toReadOnlyAccount()Returns a read-only copy of the accountPromise<WalletAccountReadOnlyTonGasless>
dispose()Disposes the wallet account, clearing private keys from memoryvoid
getAddress()

Returns the account's address.

Returns: Promise<string> - The account's TON address

Example:

const address = await account.getAddress()
console.log('Account address:', address)
sign(message)

Signs a message using the account's private key.

Parameters:

  • message (string): The message to sign

Returns: Promise<string> - The message signature

Example:

const signature = await account.sign('Hello, World!')
console.log('Signature:', signature)
verify(message, signature)

Verifies a message signature.

Parameters:

  • message (string): The original message
  • signature (string): The signature to verify

Returns: Promise<boolean> - True if the signature is valid

Example:

const isValid = await account.verify('Hello, World!', signature)
console.log('Signature valid:', isValid)
transfer(options, config?)

Transfers tokens using gasless transactions. Note: sendTransaction() is not supported and will throw an error.

Parameters:

  • options (TransferOptions): Transfer options
    • token (string): Token contract address
    • recipient (string): Recipient TON address
    • amount (number): Amount in token's base units
  • config (object, optional): Override configuration
    • paymasterToken (object, optional): Override default paymaster token
      • address (string): Paymaster token address
    • transferMaxFee (number, optional): Override maximum fee

Returns: Promise<{hash: string, fee: number}> - Transfer result

Example:

const result = await account.transfer({
  token: 'EQ...',
  recipient: 'EQ...',
  amount: 1000000000
}, {
  paymasterToken: { address: 'EQ...' },
  transferMaxFee: 2000000000
})
quoteTransfer(options)

Estimates the fee for a Jetton (TON token) transfer.

Parameters:

  • options (TransferOptions): Transfer options
    • token (string): Token contract address
    • recipient (string): Recipient TON address
    • amount (number): Amount in token's base units
  • config (object, optional): Override configuration
    • paymasterToken (object, optional): Override default paymaster token

Returns: Promise<{fee: number}> - Object containing fee estimate (in paymaster token base units)

Example:

const quote = await account.quoteTransfer({
  token: 'EQ...',
  recipient: 'EQ...',
  amount: 1000000000
});
console.log('Transfer fee estimate:', quote.fee, 'paymaster token units');
getPaymasterTokenBalance()

Returns the balance of the paymaster Jetton (used for gasless fees).

Returns: Promise<bigint> - Paymaster Jetton balance in base units

Example:

const paymasterBalance = await account.getPaymasterTokenBalance();
console.log('Paymaster Jetton balance:', paymasterBalance);
getBalance()

Returns the native TON balance (in nanotons).

Returns: Promise<bigint> - Balance in nanotons

Example:

const balance = await account.getBalance();
console.log('Balance:', balance, 'nanotons');
getTokenBalance(tokenAddress)

Returns the balance of a specific Jetton (TON token).

Parameters:

  • tokenAddress (string): The token contract address

Returns: Promise<bigint> - Token balance in base units

Example:

const tokenBalance = await account.getTokenBalance('EQ...');
console.log('Token balance:', tokenBalance, 'token base units');
dispose()

Disposes the wallet account, clearing private keys from memory.

Example:

account.dispose()

Properties

PropertyTypeDescription
indexnumberThe derivation path's index of this account
pathstringThe full derivation path of this account
keyPair{publicKey: Buffer, privateKey: Buffer}The account's public and private key pair as buffers

Example:

const { publicKey, privateKey } = account.keyPair
console.log('Public key length:', publicKey.length)
console.log('Private key length:', privateKey.length)

WalletAccountReadOnlyTonGasless

Read-only gasless TON wallet account.

Constructor

new WalletAccountReadOnlyTonGasless(publicKey, config)

Parameters:

  • publicKey (string | Uint8Array): The account's public key
  • config (TonGaslessWalletConfig): Configuration object

Methods

MethodDescriptionReturns
getAddress()Returns the account's TON addressPromise<string>
getBalance()Returns the native TON balancePromise<bigint>
getTokenBalance(tokenAddress)Returns the balance of a specific tokenPromise<bigint>
getPaymasterTokenBalance()Returns the balance of the paymaster tokenPromise<bigint>
quoteTransfer(options, config?)Estimates the fee for a token transferPromise<{fee: number}>
verify(message, signature)Verifies a message signaturePromise<boolean>
getTransactionReceipt(hash)Returns a transaction's receiptPromise<TonTransactionReceipt | null>
getAddress()

Returns the account's TON address.

Returns: Promise<string> - The account's TON address

Example:

const address = await readOnlyAccount.getAddress()
console.log('Account address:', address)
getBalance()

Returns the native TON balance (in nanotons).

Returns: Promise<bigint> - Balance in nanotons

Example:

const balance = await readOnlyAccount.getBalance()
console.log('TON balance:', balance, 'nanotons')
getTokenBalance(tokenAddress)

Returns the balance of a specific token.

Parameters:

  • tokenAddress (string): The token contract address

Returns: Promise<bigint> - Token balance in base units

Example:

const tokenBalance = await readOnlyAccount.getTokenBalance('EQ...')
console.log('Token balance:', tokenBalance, 'token base units')
getPaymasterTokenBalance()

Returns the balance of the paymaster token (used for gasless fees).

Returns: Promise<bigint> - Paymaster token balance in base units

Example:

const paymasterBalance = await readOnlyAccount.getPaymasterTokenBalance()
console.log('Paymaster token balance:', paymasterBalance)
quoteTransfer(options, config?)

Estimates the fee for a token transfer.

Parameters:

  • options (TransferOptions): Transfer options
    • token (string): Token contract address
    • recipient (string): Recipient TON address
    • amount (number): Amount in token's base units
  • config (object, optional): Override configuration
    • paymasterToken (object, optional): Override default paymaster token

Returns: Promise<{fee: number}> - Object containing fee estimate (in paymaster token base units)

Example:

const quote = await readOnlyAccount.quoteTransfer({
  token: 'EQ...',
  recipient: 'EQ...',
  amount: 1000000000
})
console.log('Transfer fee estimate:', quote.fee, 'paymaster token units')
verify(message, signature)

Verifies a message signature.

Parameters:

  • message (string): The original message
  • signature (string): The signature to verify

Returns: Promise<boolean> - True if the signature is valid

Example:

const isValid = await readOnlyAccount.verify('Hello, World!', signature)
console.log('Signature valid:', isValid)
getTransactionReceipt(hash)

Returns a transaction's receipt.

Parameters:

  • hash (string): The transaction's hash

Returns: Promise<TonTransactionReceipt | null> - The receipt, or null if the transaction has not been included in a block yet

Example:

const receipt = await readOnlyAccount.getTransactionReceipt('transaction-hash')
if (receipt) {
  console.log('Transaction receipt:', receipt)
} else {
  console.log('Transaction not yet included in a block')
}

Types

TonGaslessWalletConfig

interface TonGaslessWalletConfig {
  /**
   * TON client configuration
   */
  tonClient: {
    /**
     * TON Center API URL
     * @example 'https://toncenter.com/api/v3'
     */
    url: string;

    /**
     * Optional API key for TON Center
     */
    secretKey?: string;
  };

  /**
   * TON API client configuration
   */
  tonApiClient: {
    /**
     * TON API URL
     * @example 'https://tonapi.io/v2'
     */
    url: string;

    /**
     * Optional API key for TON API
     */
    secretKey?: string;
  };

  /**
   * Paymaster token configuration
   */
  paymasterToken: {
    /**
     * Paymaster token contract address
     * @example 'EQ...'
     */
    address: string;
  };

  /**
   * Maximum fee for transfer operations
   * @optional
   */
  transferMaxFee?: number;
}

TransferOptions

interface TransferOptions {
  /**
   * Token contract address
   * @example 'EQ...'
   */
  token: string;

  /**
   * Recipient's TON address
   * @example 'EQ...'
   */
  recipient: string;

  /**
   * Amount in token's base units
   */
  amount: number;
}

TransferResult

interface TransferResult {
  /**
   * Transaction hash
   */
  hash: string;

  /**
   * Fee paid in paymaster token units
   */
  fee: number;
}

KeyPair

interface KeyPair {
  /**
   * Public key as buffer
   */
  publicKey: Buffer;

  /**
   * Private key as buffer (sensitive data)
   */
  privateKey: Buffer;
}

Need Help?

On this page