Skip to content

Client

To use the zkSync functionality of Viem, you must extend your existing (or new) Viem Client with zkSync Actions.

Usage

import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { zkSync } from 'viem/chains'
import { eip712WalletActions } from 'viem/zksync'
 
const walletClient = createWalletClient({
  chain: zkSync,
  transport: custom(window.ethereum!),
}).extend(eip712WalletActions()) 
 
const publicClient = createPublicClient({
  chain: zkSync,
  transport: http()
})

Extensions

eip712WalletActions

A suite of Wallet Actions for suited for development with zkSync chains.

import { eip712WalletActions } from 'viem/zksync'

Sending transactions using paymaster

Read more

const hash = await walletClient.sendTransaction({
  account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1000000000000000000n,
  paymaster: '0xFD9aE5ebB0F6656f4b77a0E99dCbc5138d54b0BA',
  paymasterInput: '0x123abc...'
})

Calling contracts

Read more

import { simulateContract } from 'viem/contract'
 
const { request } = await publicClient.simulateContract(walletClient, {
  address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
  functionName: 'mint',
  args: [69420],
});
const hash = await walletClient.writeContract(request)

publicActionsL1

A suite of Public Actions suited for development with Layer 1 chains. These actions provide functionalities specific to public clients operating at the Layer 1 level, enabling them to interact seamlessly with Layer 2 protocols.

import { publicActionsL1 } from 'viem/zksync'