API Reference
Complete API documentation for @tetherto/wdk-wallet-ton-gasless
Table of Contents
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 bytesconfig(TonGaslessWalletConfig): Configuration objecttonClient(object | TonClient): TON client configuration or instanceurl(string): TON Center API URL (e.g., 'https://toncenter.com/api/v3')secretKey(string, optional): API key for TON Center
tonApiClient(object | TonApiClient): TON API client configuration or instanceurl(string): TON API URL (e.g., 'https://tonapi.io/v2')secretKey(string, optional): API key for TON API
paymasterToken(object): Paymaster token configurationaddress(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
getAccount(index)
Returns a gasless wallet account at the specified index
Promise<WalletAccountTonGasless>
getAccountByPath(path)
Returns a gasless wallet account at the specified BIP-44 derivation path
Promise<WalletAccountTonGasless>
getFeeRates()
Returns current fee rates for transactions
Promise<{normal: number, fast: number}>
dispose()
Disposes all wallet accounts, clearing private keys from memory
void
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 bytespath(string): BIP-44 derivation path (e.g., "0'/0/0")config(TonGaslessWalletConfig): Configuration object (same as WalletManagerTonGasless)
Methods
getAddress()
Returns the account's TON address
Promise<string>
sign(message)
Signs a message using the account's private key
Promise<string>
verify(message, signature)
Verifies a message signature
Promise<boolean>
transfer(options, config?)
Transfers tokens using gasless transactions
Promise<{hash: string, fee: number}>
quoteTransfer(options, config?)
Estimates the fee for a token transfer
Promise<{fee: number}>
getBalance()
Returns the native TON balance (in nanotons)
Promise<number>
getTokenBalance(tokenAddress)
Returns the balance of a specific token
Promise<number>
getPaymasterTokenBalance()
Returns the balance of the paymaster token
Promise<number>
toReadOnlyAccount()
Returns a read-only copy of the account
Promise<WalletAccountReadOnlyTonGasless>
dispose()
Disposes the wallet account, clearing private keys from memory
void
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 messagesignature(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 optionstoken(string): Token contract addressrecipient(string): Recipient TON addressamount(number): Amount in token's base units
config(object, optional): Override configurationpaymasterToken(object, optional): Override default paymaster tokenaddress(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 optionstoken(string): Token contract addressrecipient(string): Recipient TON addressamount(number): Amount in token's base units
config(object, optional): Override configurationpaymasterToken(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<number> - 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<number> - 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<number> - 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
index
number
The derivation path's index of this account
path
string
The 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 keyconfig(TonGaslessWalletConfig): Configuration object
Methods
getAddress()
Returns the account's TON address
Promise<string>
getBalance()
Returns the native TON balance
Promise<number>
getTokenBalance(tokenAddress)
Returns the balance of a specific token
Promise<number>
getPaymasterTokenBalance()
Returns the balance of the paymaster token
Promise<number>
quoteTransfer(options, config?)
Estimates the fee for a token transfer
Promise<{fee: number}>
getTransactionReceipt(hash)
Returns a transaction's receipt
Promise<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<number> - 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<number> - 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<number> - 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 optionstoken(string): Token contract addressrecipient(string): Recipient TON addressamount(number): Amount in token's base units
config(object, optional): Override configurationpaymasterToken(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')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;
}
