API Reference

Complete API documentation for @tetherto/wdk-wallet-tron

Table of Contents

Class
Description
Methods

Main class for managing Tron wallets. Extends WalletManager from @tetherto/wdk-wallet.

Individual Tron wallet account implementation. Extends WalletAccountReadOnlyTron and implements IWalletAccount.

Read-only Tron wallet account. Extends WalletAccountReadOnly from @tetherto/wdk-wallet.

WalletManagerTron

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

Fee Rate Constants

const FEE_RATE_NORMAL_MULTIPLIER = 1.1
const FEE_RATE_FAST_MULTIPLIER = 2.0

Constructor

new WalletManagerTron(seed, config?)

Parameters:

  • seed (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes

  • config (TronWalletConfig, optional): Configuration object

    • provider (string | TronWeb, optional): Tron RPC endpoint URL or TronWeb instance

    • transferMaxFee (number, optional): Maximum fee amount for transfer operations (in sun)

Example:

Methods

Method
Description
Returns
Throws

getAccount(index?)

Returns a wallet account at the specified index

Promise<WalletAccountTron>

-

getAccountByPath(path)

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

Promise<WalletAccountTron>

-

getFeeRates()

Returns current fee rates from Tron network

Promise<{normal: number, fast: number}>

If no provider

dispose()

Disposes all wallet accounts, clearing private keys from memory

void

-

getAccount(index?)

Returns a wallet account at the specified index using Tron's BIP-44 derivation (m/44'/195').

Parameters:

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

Returns: Promise<WalletAccountTron> - The wallet account

Example:

getAccountByPath(path)

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

Parameters:

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

Returns: Promise<WalletAccountTron> - The wallet account

Example:

getFeeRates()

Returns current fee rates from Tron network chain parameters.

Returns: Promise<{normal: number, fast: number}> - Fee rates in sun

  • normal: Base fee × 1.1

  • fast: Base fee × 2.0

Throws: Error if no TronWeb provider is configured

Example:

dispose()

Disposes all wallet accounts, clearing private keys from memory.

Example:

WalletAccountTron

Represents an individual Tron wallet account. Extends WalletAccountReadOnlyTron and implements IWalletAccount.

Constants

Constructor

Parameters:

  • seed (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes

  • path (string): BIP-44 derivation path (e.g., "0'/0/0")

  • config (TronWalletConfig, optional): Configuration object

Throws: Error if seed phrase is invalid (BIP-39 validation fails)

Example:

Methods

Method
Description
Returns
Throws

getAddress()

Returns the account's Tron 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>

-

sendTransaction(tx)

Sends a Tron transaction

Promise<{hash: string, fee: number}>

If no provider or fee exceeds max

quoteSendTransaction(tx)

Estimates the fee for a Tron transaction

Promise<{fee: number}>

If no provider

transfer(options)

Transfers TRC20 tokens to another address

Promise<{hash: string, fee: number}>

If no provider or fee exceeds max

quoteTransfer(options)

Estimates the fee for a TRC20 transfer

Promise<{fee: number}>

If no provider

getBalance()

Returns the native TRX balance (in sun)

Promise<number>

If no provider

getTokenBalance(tokenAddress)

Returns the balance of a specific TRC20 token

Promise<number>

If no provider

toReadOnlyAccount()

Returns a read-only copy of the account

Promise<WalletAccountReadOnlyTron>

-

dispose()

Disposes the wallet account, clearing private keys from memory

void

-

getAddress()

Returns the account's Tron address (starts with 'T').

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

Example:

sign(message)

Signs a message using Keccak-256 hash and secp256k1 signature.

Parameters:

  • message (string): The message to sign (UTF-8 encoded)

Returns: Promise<string> - The message signature (hex string)

Example:

verify(message, signature)

Verifies a message signature using secp256k1.

Parameters:

  • message (string): The original message

  • signature (string): The signature to verify (hex string)

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

Example:

sendTransaction(tx)

Sends a TRX transaction and returns the result with hash and fee.

Parameters:

  • tx (TronTransaction): The transaction object

    • to (string): Recipient Tron address (e.g., 'T...')

    • value (number): Amount in sun (1 TRX = 1,000,000 sun)

Returns: Promise<{hash: string, fee: number}> - Transaction hash and fee in sun

Throws:

  • Error if no TronWeb provider is configured

  • Error if fee exceeds transferMaxFee

Example:

quoteSendTransaction(tx)

Estimates the bandwidth cost for a TRX transaction.

Parameters:

  • tx (TronTransaction): The transaction object (same as sendTransaction)

Returns: Promise<{fee: number}> - Fee estimate in sun

Throws: Error if no TronWeb provider is configured

Example:

transfer(options)

Transfers TRC20 tokens using smart contract call.

Parameters:

  • options (TransferOptions): Transfer options

    • token (string): TRC20 contract address (e.g., 'T...')

    • recipient (string): Recipient Tron address (e.g., 'T...')

    • amount (number | bigint): Amount in token's base units

Returns: Promise<{hash: string, fee: number}> - Transaction hash and fee in sun

Throws:

  • Error if no TronWeb provider is configured

  • Error if fee exceeds transferMaxFee

Example:

quoteTransfer(options)

Estimates the energy and bandwidth cost for a TRC20 token transfer.

Parameters:

  • options (TransferOptions): Transfer options (same as transfer)

Returns: Promise<{fee: number}> - Fee estimate in sun (energy + bandwidth costs)

Throws: Error if no TronWeb provider is configured

Example:

getBalance()

Returns the native TRX balance.

Returns: Promise<number> - Balance in sun

Throws: Error if no TronWeb provider is configured

Example:

getTokenBalance(tokenAddress)

Returns the balance of a specific TRC20 token.

Parameters:

  • tokenAddress (string): The TRC20 contract address (e.g., 'T...')

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

Throws: Error if no TronWeb provider is configured

Example:

toReadOnlyAccount()

Creates a read-only copy of the account.

Returns: Promise<WalletAccountReadOnlyTron> - Read-only account instance

Example:

dispose()

Disposes the wallet account, clearing private keys from memory using sodium_memzero.

Example:

Properties

Property
Type
Description

index

number

The derivation path's index of this account

path

string

The full BIP-44 derivation path of this account

keyPair

{privateKey: Buffer, publicKey: Buffer}

The account's key pair (⚠️ Contains sensitive data)

Example:

⚠️ Security Note: The keyPair property contains sensitive cryptographic material. Never log, display, or expose the private key.

WalletAccountReadOnlyTron

Represents a read-only Tron wallet account that can query balances and estimate fees but cannot send transactions.

Constructor

Parameters:

  • address (string): The account's Tron address

  • config (Omit<TronWalletConfig, 'transferMaxFee'>, optional): Configuration object without transferMaxFee

Example:

Methods

Method
Description
Returns
Throws

getBalance()

Returns the native TRX balance (in sun)

Promise<number>

If no provider

getTokenBalance(tokenAddress)

Returns the balance of a specific TRC20 token

Promise<number>

If no provider

quoteSendTransaction(tx)

Estimates the fee for a TRX transaction

Promise<{fee: number}>

If no provider

quoteTransfer(options)

Estimates the fee for a TRC20 transfer

Promise<{fee: number}>

If no provider

getTransactionReceipt(hash)

Returns a transaction's receipt

Promise<TronTransactionReceipt | null>

If no provider

getBalance()

Returns the native TRX balance.

Returns: Promise<number> - Balance in sun

Throws: Error if no TronWeb provider is configured

Example:

getTokenBalance(tokenAddress)

Returns the balance of a specific TRC20 token.

Parameters:

  • tokenAddress (string): The TRC20 contract address

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

Throws: Error if no TronWeb provider is configured

Example:

quoteSendTransaction(tx)

Estimates the bandwidth cost for a TRX transaction.

Parameters:

  • tx (TronTransaction): The transaction object

Returns: Promise<{fee: number}> - Fee estimate in sun

Throws: Error if no TronWeb provider is configured

quoteTransfer(options)

Estimates the energy and bandwidth cost for a TRC20 transfer.

Parameters:

  • options (TransferOptions): Transfer options

Returns: Promise<{fee: number}> - Fee estimate in sun

Throws: Error if no TronWeb provider is configured

getTransactionReceipt(hash)

Returns a transaction's receipt if it has been processed.

Parameters:

  • hash (string): The transaction hash

Returns: Promise<TronTransactionReceipt | null> - Transaction receipt or null

Throws: Error if no TronWeb provider is configured

Types

TronWalletConfig

TronTransaction

TransferOptions

TransactionResult

TransferResult

Constants


Need Help?