API Reference

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

Table of Contents

Class
Description
Methods

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

Individual ERC-4337 wallet account implementation. Extends WalletAccountReadOnlyEvmErc4337 and implements IWalletAccount.

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

WalletManagerEvmErc4337

The main class for managing ERC-4337 EVM 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 WalletManagerEvmErc4337(seed, config)

Parameters:

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

  • config (EvmErc4337WalletConfig, optional): Configuration object

    • chainId (number): The blockchain's ID (e.g., 1 for Ethereum mainnet)

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

    • bundlerUrl (string): The URL of the bundler service

    • paymasterUrl (string): The URL of the paymaster service

    • paymasterAddress (string): The address of the paymaster smart contract

    • entryPointAddress (string): The address of the entry point smart contract

    • safeModulesVersion (string): The Safe modules version

    • paymasterToken (object): The paymaster token configuration

      • address (string): The address of the paymaster token

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

Example:

Methods

Method
Description
Returns
Throws

getAccount(index?)

Returns a wallet account at the specified index

Promise<WalletAccountEvmErc4337>

-

getAccountByPath(path)

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

Promise<WalletAccountEvmErc4337>

-

getFeeRates()

Returns current fee rates for transactions

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 BIP-44 derivation.

Parameters:

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

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

Example:

getFeeRates()

Returns current fee rates with ERC-4337 specific multipliers.

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

Throws: Error if no provider is configured

Example:

dispose()

Disposes all wallet accounts, clearing private keys from memory.

Example:

WalletAccountEvmErc4337

Represents an individual ERC-4337 wallet account. Extends WalletAccountReadOnlyEvmErc4337 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 (EvmErc4337WalletConfig): Configuration object (same as WalletManagerEvmErc4337)

Example:

Methods

Methods

Method
Description
Returns
Throws

getAddress()

Returns the Safe account's 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, config?)

Sends a gasless transaction via UserOperation

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

If fee exceeds max

quoteSendTransaction(tx, config?)

Estimates the fee for a UserOperation

Promise<{fee: number}>

-

transfer(options, config?)

Transfers ERC20 tokens via UserOperation

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

If fee exceeds max

quoteTransfer(options, config?)

Estimates the fee for an ERC20 transfer

Promise<{fee: number}>

-

getBalance()

Returns the native token balance (in wei)

Promise<number>

-

getTokenBalance(tokenAddress)

Returns the balance of a specific ERC20 token

Promise<number>

-

getPaymasterTokenBalance()

Returns the paymaster token balance

Promise<number>

-

toReadOnlyAccount()

Returns a read-only copy of the account

Promise<WalletAccountReadOnlyEvmErc4337>

-

dispose()

Disposes the wallet account, clearing private keys from memory

void

-

getAddress()

Returns the Safe smart contract wallet address (not the underlying EOA address).

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

Example:

sign(message)

Signs a message using the underlying EOA private key.

Parameters:

  • message (string): The message to sign

Returns: Promise<string> - The message signature

Example:

verify(message, signature)

Verifies a message signature against the underlying EOA address.

Parameters:

  • message (string): The original message

  • signature (string): The signature to verify

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

Example:

sendTransaction(tx, config?)

Sends a gasless transaction via UserOperation through the bundler.

Parameters:

  • tx (EvmTransaction | EvmTransaction[]): Transaction object or array for batch transactions

    • to (string): Recipient address

    • value (number): Amount in wei

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

  • config (optional object): Override configuration

    • paymasterToken (object): Override paymaster token

Returns: Promise<{hash: string, fee: number}> - UserOperation hash and fee in paymaster token units

Throws: Error if fee exceeds transferMaxFee

Example:

quoteSendTransaction(tx, config?)

Estimates the fee for a UserOperation without sending it.

Parameters:

  • tx (EvmTransaction | EvmTransaction[]): Transaction object or array (same as sendTransaction)

  • config (optional object): Override configuration (same as sendTransaction)

Returns: Promise<{fee: number}> - Fee estimate in paymaster token units

Example:

transfer(options, config?)

Transfers ERC20 tokens via UserOperation with gasless execution.

Parameters:

  • options (TransferOptions): Transfer options

    • token (string): ERC20 token contract address

    • recipient (string): Recipient address

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

  • config (optional object): Override configuration

    • paymasterToken (object): Override paymaster token

    • transferMaxFee (number): Override maximum fee limit

Returns: Promise<{hash: string, fee: number}> - UserOperation hash and fee in paymaster token units

Throws:

  • Error if fee exceeds transferMaxFee

  • Error if insufficient paymaster token balance

Example:

quoteTransfer(options, config?)

Estimates the fee for an ERC20 token transfer.

Parameters:

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

  • config (optional object): Override configuration (same as transfer)

Returns: Promise<{fee: number}> - Fee estimate in paymaster token units

Example:

getBalance()

Returns the Safe account's native token balance.

Returns: Promise<number> - Balance in wei

Example:

getTokenBalance(tokenAddress)

Returns the balance of a specific ERC20 token in the Safe account.

Parameters:

  • tokenAddress (string): The ERC20 token contract address

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

Example:

getPaymasterTokenBalance()

Returns the balance of the configured paymaster token used for paying fees.

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

Example:

toReadOnlyAccount()

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

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

Example:

dispose()

Disposes the wallet account, clearing private keys 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: 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.

WalletAccountReadOnlyEvmErc4337

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

Constructor

Parameters:

  • address (string): The EOA address (owner address)

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

Example:

Methods

Method
Description
Returns
Throws

getAddress()

Returns the Safe account's address

Promise<string>

-

getBalance()

Returns the native token balance (in wei)

Promise<number>

-

getTokenBalance(tokenAddress)

Returns the balance of a specific ERC20 token

Promise<number>

-

getPaymasterTokenBalance()

Returns the paymaster token balance

Promise<number>

-

quoteSendTransaction(tx, config?)

Estimates the fee for a UserOperation

Promise<{fee: number}>

If simulation fails

quoteTransfer(options, config?)

Estimates the fee for an ERC20 transfer

Promise<{fee: number}>

If simulation fails

getTransactionReceipt(hash)

Returns a transaction's receipt by UserOperation hash

Promise<EvmTransactionReceipt | null>

-

getAddress()

Returns the Safe smart contract wallet address.

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

Example:

getBalance()

Returns the Safe account's native token balance.

Returns: Promise<number> - Balance in wei

Example:

getTokenBalance(tokenAddress)

Returns the balance of a specific ERC20 token.

Parameters:

  • tokenAddress (string): The ERC20 token contract address

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

Example:

getPaymasterTokenBalance()

Returns the balance of the configured paymaster token.

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

Example:

quoteSendTransaction(tx, config?)

Estimates the fee for a UserOperation.

Parameters:

  • tx (EvmTransaction | EvmTransaction[]): Transaction object or array

  • config (optional object): Override paymaster token

Returns: Promise<{fee: number}> - Fee estimate in paymaster token units

Throws: Error if simulation fails or insufficient paymaster funds

Example:

quoteTransfer(options, config?)

Estimates the fee for an ERC20 token transfer.

Parameters:

  • options (TransferOptions): Transfer options

  • config (optional object): Override paymaster token

Returns: Promise<{fee: number}> - Fee estimate in paymaster token units

Example:

getTransactionReceipt(hash)

Returns a transaction's receipt by UserOperation hash.

Parameters:

  • hash (string): The UserOperation hash

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

Example:

Types

EvmErc4337WalletConfig

EvmTransaction

TransferOptions

TransactionResult

TransferResult

Constants


Need Help?