githubEdit

codeAPI Reference

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

Table of Contents

Class
Description
Methods

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

Individual EVM wallet account implementation. Extends WalletAccountReadOnlyEvm and implements IWalletAccount from @tetherto/wdk-wallet.

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

WalletManagerEvm

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

Constructor

new WalletManagerEvm(seed, config?)

Parameters:

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

  • config (object, optional): Configuration object

    • provider (string | Eip1193Provider, optional): RPC endpoint URL or EIP-1193 provider instance

    • transferMaxFee (number | bigint, optional): Maximum fee amount for transfer operations (in wei)

Example:

const wallet = new WalletManagerEvm(seedPhrase, {
  provider: 'https://rpc.mevblocker.io/fast',
  transferMaxFee: 100000000000000 // Maximum fee in wei
})

Methods

Method
Description
Returns
Throws

getRandomSeedPhrase(wordCount?)

(static) Returns a random BIP-39 seed phrase

string

-

isValidSeedPhrase(seedPhrase)

(static) Checks if a seed phrase is valid

boolean

-

getAccount(index?)

Returns a wallet account at the specified index

Promise<WalletAccountEvm>

-

getAccountByPath(path)

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

Promise<WalletAccountEvm>

-

getFeeRates()

Returns current fee rates for transactions

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

If no provider is set

dispose()

Disposes all wallet accounts, clearing private keys from memory

void

-

Properties

Property
Type
Description

seed

Uint8Array

The wallet's seed bytes

getRandomSeedPhrase(wordCount?) (static)

Returns a random BIP-39 seed phrase.

Parameters:

  • wordCount (12 | 24, optional): The number of words in the seed phrase (default: 12)

Returns: string - The seed phrase

Example:

isValidSeedPhrase(seedPhrase) (static)

Checks if a seed phrase is valid.

Parameters:

  • seedPhrase (string): The seed phrase to validate

Returns: boolean - True if the seed phrase is valid

Example:

getAccount(index?)

Returns a wallet account at the specified index following BIP-44 standard.

Parameters:

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

Returns: Promise<WalletAccountEvm> - 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<WalletAccountEvm> - The wallet account

Example:

getFeeRates()

Returns current fee rates based on network conditions with predefined multipliers.

Returns: Promise<{normal: bigint, fast: bigint}> - Fee rates in wei

  • normal: Base fee × 1.1 (10% above base)

  • fast: Base fee × 2.0 (100% above base)

Throws: Error if no provider is configured

Example:

dispose()

Disposes all wallet accounts, clearing private keys from memory.

Example:

WalletAccountEvm

Represents an individual wallet account. Extends WalletAccountReadOnlyEvm and implements IWalletAccount from @tetherto/wdk-wallet.

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 (object, optional): Configuration object

    • provider (string | Eip1193Provider, optional): RPC endpoint URL or EIP-1193 provider instance

    • transferMaxFee (number | bigint, optional): Maximum fee amount for transfer operations (in wei)

Throws:

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

Example:

Methods

Method
Description
Returns
Throws

getAddress()

Returns the account's address

Promise<string>

-

sign(message)

Signs a message using the account's private key

Promise<string>

-

signTypedData(typedData)

Signs typed data according to EIP-712

Promise<string>

-

verify(message, signature)

Verifies a message signature

Promise<boolean>

-

verifyTypedData(typedData, signature)

Verifies a typed data signature (EIP-712)

Promise<boolean>

-

sendTransaction(tx)

Sends an EVM transaction

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

If no provider

quoteSendTransaction(tx)

Estimates the fee for an EVM transaction

Promise<{fee: bigint}>

If no provider

transfer(options)

Transfers ERC20 tokens to another address

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

If no provider or fee exceeds max

quoteTransfer(options)

Estimates the fee for an ERC20 transfer

Promise<{fee: bigint}>

If no provider

getBalance()

Returns the native token balance (in wei)

Promise<bigint>

If no provider

getTokenBalance(tokenAddress)

Returns the balance of a specific ERC20 token

Promise<bigint>

If no provider

getTokenBalances(tokenAddresses)

Returns balances for multiple ERC20 tokens

Promise<Record<string, bigint>>

If no provider

approve(options)

Approves a spender to spend tokens

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

If no provider

getAllowance(token, spender)

Returns current allowance for a spender

Promise<bigint>

If no provider

getTransactionReceipt(hash)

Returns a transaction's receipt

Promise<EvmTransactionReceipt | null>

If no provider

toReadOnlyAccount()

Returns a read-only copy of the account

Promise<WalletAccountReadOnlyEvm>

-

dispose()

Disposes the wallet account, clearing private keys from memory

void

-

getAddress()

Returns the account's Ethereum address.

Returns: Promise<string> - Checksummed Ethereum address

Example:

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:

signTypedData(typedData)

Signs typed data according to EIP-712arrow-up-right.

Parameters:

  • typedData (TypedData): The typed data to sign

    • domain (TypedDataDomain): The domain separator (name, version, chainId, verifyingContract)

    • types (Record<string, TypedDataField[]>): The type definitions

    • message (Record<string, unknown>): The message data

Returns: Promise<string> - The typed data signature

Example:

verify(message, signature)

Verifies a message signature against the account's address.

Parameters:

  • message (string): The original message

  • signature (string): The signature to verify

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

Example:

verifyTypedData(typedData, signature)

Verifies a typed data signature according to EIP-712arrow-up-right.

Parameters:

  • typedData (TypedData): The typed data that was signed

  • signature (string): The signature to verify

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

Example:

sendTransaction(tx)

Sends an EVM transaction and returns the result with hash and fee.

Parameters:

  • tx (EvmTransaction): The transaction object

    • to (string): Recipient address

    • value (number | bigint): Amount in wei

    • data (string, optional): Transaction data in hex format

    • gasLimit (number | bigint, optional): Maximum gas units

    • gasPrice (number | bigint, optional): Legacy gas price in wei

    • maxFeePerGas (number | bigint, optional): EIP-1559 max fee per gas in wei

    • maxPriorityFeePerGas (number | bigint, optional): EIP-1559 max priority fee per gas in wei

Returns: Promise<{hash: string, fee: bigint}> - Transaction result

Throws: Error if no provider is configured

Example:

quoteSendTransaction(tx)

Estimates the fee for an EVM transaction without sending it.

Parameters:

  • tx (EvmTransaction): The transaction object (same format as sendTransaction)

Returns: Promise<{fee: bigint}> - Fee estimate in wei

Throws: Error if no provider is configured

Example:

transfer(options)

Transfers ERC20 tokens to another address using the standard transfer function.

Parameters:

  • options (TransferOptions): Transfer options

    • token (string): Token contract address

    • recipient (string): Recipient address

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

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

Throws:

  • Error if no provider is configured

  • Error if fee exceeds transferMaxFee (if configured)

Example:

quoteTransfer(options)

Estimates the fee for an ERC20 token transfer.

Parameters:

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

Returns: Promise<{fee: bigint}> - Fee estimate in wei

Throws: Error if no provider is configured

Example:

getBalance()

Returns the native token balance (ETH, MATIC, BNB, etc.).

Returns: Promise<bigint> - Balance in wei

Throws: Error if no provider is configured

Example:

getTokenBalance(tokenAddress)

Returns the balance of a specific ERC20 token using the balanceOf function.

Parameters:

  • tokenAddress (string): The ERC20 token contract address

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

Throws: Error if no provider is configured

Example:

getTokenBalances(tokenAddresses)

Returns balances for multiple ERC20 tokens in one call.

Parameters:

  • tokenAddresses (string[]): List of ERC20 token contract addresses

Returns: Promise<Record<string, bigint>> - Object mapping each token address to its balance in base units

Throws: Error if no provider is configured

Example:

approve(options)

Approves a specific amount of tokens to a spender.

Parameters:

  • options (ApproveOptions): Approve options

    • token (string): Token contract address

    • spender (string): Spender address

    • amount (number | bigint): Amount to approve

Returns: Promise<{hash: string, fee: bigint}> - Transaction result

Throws:

  • Error if no provider is configured

  • Error if trying to re-approve USDT on Ethereum without resetting to 0 first

Example:

getAllowance(token, spender)

Returns the current token allowance for the given spender.

Parameters:

  • token (string): ERC20 token contract address

  • spender (string): The spender's address

Returns: Promise<bigint> - The current allowance

Throws: Error if no provider is configured

Example:

getTransactionReceipt(hash)

Returns a transaction receipt by hash.

Parameters:

  • hash (string): The transaction hash

Returns: Promise<EvmTransactionReceipt | null> - Transaction receipt or null if not mined

Throws: Error if no provider is configured

Example:

toReadOnlyAccount()

Creates a read-only copy of the account with the same configuration.

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

Example:

dispose()

Disposes the wallet account, erasing the private key from memory.

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: Uint8Array | null, publicKey: Uint8Array}

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

address

string

The account's Ethereum address (inherited from WalletAccountReadOnlyEvm)

Example:

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

WalletAccountReadOnlyEvm

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

Constructor

Parameters:

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

  • config (Omit<EvmWalletConfig, 'transferMaxFee'>, optional): Configuration object (same as EvmWalletConfig but without transferMaxFee, since read-only accounts cannot send transactions)

    • provider (string | Eip1193Provider, optional): RPC endpoint URL or EIP-1193 provider instance

Example:

Properties

Property
Type
Description

address

string

The account's Ethereum address

Methods

Method
Description
Returns
Throws

getAddress()

Returns the account's address

Promise<string>

-

getBalance()

Returns the native token balance (in wei)

Promise<bigint>

If no provider

getTokenBalance(tokenAddress)

Returns the balance of a specific ERC20 token

Promise<bigint>

If no provider

getTokenBalances(tokenAddresses)

Returns balances for multiple ERC20 tokens

Promise<Record<string, bigint>>

If no provider

quoteSendTransaction(tx)

Estimates the fee for an EVM transaction

Promise<{fee: bigint}>

If no provider

quoteTransfer(options)

Estimates the fee for an ERC20 transfer

Promise<{fee: bigint}>

If no provider

verify(message, signature)

Verifies a message signature

Promise<boolean>

-

verifyTypedData(typedData, signature)

Verifies a typed data signature (EIP-712)

Promise<boolean>

-

getTransactionReceipt(hash)

Returns a transaction's receipt

Promise<EvmTransactionReceipt | null>

If no provider

getAllowance(token, spender)

Returns current allowance for a spender

Promise<bigint>

If no provider

getAddress()

Returns the account's Ethereum address.

Returns: Promise<string> - Checksummed Ethereum address

Example:

getBalance()

Returns the account's native token balance.

Returns: Promise<bigint> - Balance in wei

Throws: Error if no provider is configured

Example:

getTokenBalance(tokenAddress)

Returns the balance of a specific ERC20 token.

Parameters:

  • tokenAddress (string): The ERC20 token contract address

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

Throws: Error if no provider is configured

Example:

getTokenBalances(tokenAddresses)

Returns balances for multiple ERC20 tokens.

Parameters:

  • tokenAddresses (string[]): List of ERC20 token contract addresses

Returns: Promise<Record<string, bigint>> - Object mapping each token address to its balance in base units

Throws: Error if no provider is configured

Example:

quoteSendTransaction(tx)

Estimates the fee for an EVM transaction.

Parameters:

  • tx (EvmTransaction): The transaction object

Returns: Promise<{fee: bigint}> - Fee estimate in wei

Throws: Error if no provider is configured

Example:

quoteTransfer(options)

Estimates the fee for an ERC20 token transfer.

Parameters:

  • options (TransferOptions): Transfer options

Returns: Promise<{fee: bigint}> - Fee estimate in wei

Throws: Error if no provider is configured

Example:

verify(message, signature)

Verifies a message signature against the account's address.

Parameters:

  • message (string): The original message

  • signature (string): The signature to verify

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

Example:

verifyTypedData(typedData, signature)

Verifies a typed data signature according to EIP-712arrow-up-right.

Parameters:

  • typedData (TypedData): The typed data that was signed

  • signature (string): The signature to verify

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

Example:

getTransactionReceipt(hash)

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

Parameters:

  • hash (string): The transaction hash

Returns: Promise<EvmTransactionReceipt | null> - Transaction receipt or null if not yet mined

Throws: Error if no provider is configured

Example:

getAllowance(token, spender)

Returns the current allowance for the given token and spender.

Parameters:

  • token (string): The token's address

  • spender (string): The spender's address

Returns: Promise<bigint> - The allowance

Example:

Types

EvmTransaction

TransferOptions

TransactionResult

TransferResult

FeeRates

KeyPair

TypedData

TypedDataDomain

TypedDataField

EvmWalletConfig

ApproveOptions

EvmTransactionReceipt


Need Help?