Usage

Installation, quick start, and usage examples for @tetherto/wdk-wallet-evm-erc-4337

Installation

To install the @tetherto/wdk-wallet-evm-erc-4337 package, follow these instructions:

npm install @tetherto/wdk-wallet-evm-erc-4337

Quick Start

Importing from @tetherto/wdk-wallet-evm-erc-4337

  1. WalletManagerEvmErc4337: Main class for managing ERC-4337 wallets

  2. WalletAccountEvmErc4337: Use this for full access accounts

  3. WalletAccountReadOnlyEvmErc4337: Use this for read-only accounts

Creating a New Wallet

import WalletManagerEvmErc4337, { 
  WalletAccountEvmErc4337, 
  WalletAccountReadOnlyEvmErc4337 
} from '@tetherto/wdk-wallet-evm-erc-4337'

// Use a BIP-39 seed phrase (replace with your own secure phrase)
const seedPhrase = 'your twelve word seed phrase here' // Replace with actual seed generation


// Create wallet manager with ERC-4337 configuration
const wallet = new WalletManagerEvmErc4337(seedPhrase, {
  chainId: 1, // Ethereum mainnet
  provider: 'https://rpc.mevblocker.io/fast',
  bundlerUrl: 'https://api.candide.dev/public/v3/ethereum',
  paymasterUrl: 'https://api.candide.dev/public/v3/ethereum',
  paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
  entryPointAddress: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
  safeModulesVersion: '1.0.0',
  paymasterToken: {
    address: '0xdAC17F958D2ee523a2206206994597C13D831ec7'
  },
  
  // Optional parameter
  transferMaxFee: 100000000000000 // Optional: Maximum fee amount for transfer operations (in wei)

})

// Create a read-only account
const readOnlyAccount = new WalletAccountReadOnlyEvmErc4337('0x...', { // Smart contract wallet address
  chainId: 1, // Required: Blockchain ID
  provider: 'https://rpc.mevblocker.io/fast', // Required: RPC provider
  bundlerUrl: 'https://api.candide.dev/public/v3/ethereum', // Required: Bundler service
  paymasterUrl: 'https://api.candide.dev/public/v3/ethereum', // Required: Paymaster service
  paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba', // Required: Paymaster contract
  entryPointAddress: '0x0000000071727De22E5E9d8BAf0edAc6f37da032', // Required: EntryPoint contract
  safeModulesVersion: '1.0.0', // Required: Safe modules version
  paymasterToken: { // Required: Paymaster token configuration
    address: '0xdAC17F958D2ee523a2206206994597C13D831ec7' // USDT token address
  }
})

To use test/mock tokens instead of real funds, see the Testnet configuration section.

Managing Multiple Accounts

Checking Balances

Owned Account

For accounts where you have the seed phrase and full access:

Read-Only Account

For addresses where you don't have the seed phrase:

Sending Gasless Transactions

Token Transfers with Gasless Transactions

Memory Management

Complete Examples

Complete Wallet Setup

Gasless Transaction Example

Multi-Token Fee Payment

Token Transfer with Gasless Fees


Need Help?