Skip to main content

At a glance

  • Factory: createViemClient({ l1, l2, l1Wallet, l2Wallet?, overrides? }) → ViemClient
  • What it provides: cached core addresses, typed contracts, convenience wallet access (L2 wallet derivation), and ZKsync RPC bound to l2.
  • When to use: create this first; then pass into createViemSdk(client).

Import

Quick start

l1Wallet.account is required. If you omit l2Wallet, use client.getL2Wallet(); it lazily reuses the L1 account over the L2 transport.

createViemClient(args) → ViemClient

Returns: ViemClient

ViemClient interface

'viem'
Adapter discriminator.
viem.PublicClient
Public L1 client.
viem.PublicClient
Public L2 (ZKsync) client.
viem.WalletClient<T, C, A>
Wallet bound to L1 (carries default account).
viem.WalletClient<T, C, A> | undefined
Optional pre-supplied L2 wallet.
viem.Account
Default account (from l1Wallet).
ZksRpc
ZKsync-specific RPC bound to l2.

Methods

ensureAddresses() → Promise<ResolvedAddresses>

Resolve and cache core contract addresses from chain state (merges any overrides).

contracts() → Promise<{ ...contracts }>

Return typed viem contracts (getContract) connected to the current clients.

refresh(): void

Clear cached addresses/contracts. Subsequent calls re-resolve.

baseToken(chainId: bigint) → Promise<Address>

Return the L1 base-token address for a given L2 chain via Bridgehub.baseToken(chainId).

getL2Wallet() → viem.WalletClient

Return the L2 wallet. If not provided at construction, lazily creates one from the same account as l1Wallet over the L2 transport.

Types

ResolvedAddresses

Notes & pitfalls

  • Wallet placement: Deposits sign on L1; withdrawals sign on L2; finalization signs on L1 (via SDK).
  • Caching: ensureAddresses() and contracts() are cached. Use refresh() after network/override changes.
  • Overrides: For forks or custom deployments, pass overrides at construction; they’ll be merged with on-chain lookups.
  • Error surface: Methods may throw typed errors; use the SDK’s try* variants (on resources) if you prefer result objects.