WDK logoWDK documentation
StartWalletsDeFi & FiatAI & CLITools

Manage Accounts

Work with multiple smart accounts, custom derivation paths, and known Safe addresses.

This guide explains how to retrieve accounts by index, use custom derivation paths, and read a known Safe address.

Retrieve Accounts by Index

You can retrieve multiple smart accounts using wallet.getAccount() with different index values:

Retrieve Multiple Accounts
const account0 = await wallet.getAccount(0)
const address0 = await account0.getAddress()
console.log('Account 0 address:', address0)

const account1 = await wallet.getAccount(1)
const address1 = await account1.getAddress()
console.log('Account 1 address:', address1)

Retrieve Account by Custom Derivation Path

You can retrieve an account at a specific derivation path using wallet.getAccountByPath():

Custom Derivation Path
const customAccount = await wallet.getAccountByPath("0'/0/5")
const customAddress = await customAccount.getAddress()
console.log('Custom account address:', customAddress)

Read a Known Safe Address

Use WalletAccountReadOnlyEvmErc4337.fromSafeAddress() when your app already has the Safe address. It does not need a seed phrase or owner address. The ordinary read-only constructor instead takes an owner EOA address and predicts a Safe address from it.

  1. Obtain the Safe address from your application and select its network configuration.
  2. Pass that address and configuration to the read-only factory.
  3. Confirm that getAddress() returns the supplied address in checksummed form.

The example below derives a counterfactual Safe from an upstream test owner to demonstrate the factory. It does not deploy or fund the Safe; use your application's known Safe address for actual balance monitoring.

Read a Known Safe Address
import { WalletAccountReadOnlyEvmErc4337 } from '@tetherto/wdk-wallet-evm-erc-4337'

const config = {
  chainId: 1,
  provider: 'https://rpc.mevblocker.io/fast',
  bundlerUrl: 'https://api.candide.dev/public/v3/1',
  safeModulesVersion: '0.3.0',
  useNativeCoins: true
}

// Derivation fixture only; this does not prove the Safe is deployed.
const safeAddress = WalletAccountReadOnlyEvmErc4337.predictSafeAddress(
  '0x405005C7c4422390F4B334F64Cf20E0b767131d0',
  { safeModulesVersion: '0.3.0' }
)
const readOnlyAccount = WalletAccountReadOnlyEvmErc4337.fromSafeAddress(
  safeAddress,
  config
)
console.log('Safe address:', await readOnlyAccount.getAddress())

The factory returns an account synchronously and does not check deployment, discover the owner, or validate that the supplied address is a Safe contract. It can read balances and allowances, but cannot sign or send transactions. Its owner is unknown, so signature verification is unavailable.

Non-sponsored quotes require this Safe to be deployed before the module can build a UserOperation. A sponsored quote returns a zero fee without checking deployment or sponsorship eligibility; see known-Safe errors.

Next Steps

With accounts set up, learn how to check balances.

On this page