This repository contains an example that uses Viem with EIP712 changes and Wagmi-beta to interact with ZkSync chain. It can send transactions and call contract methods.
To send an EIP712 transaction an sendEip712Transaction Viem action must be used:
import { useConnectorClient } from 'wagmi'
import { sendEip712Transaction } from 'viem_zksync_chains/zksync'
// wallet connection setup...
const { data: walletClient } = useConnectorClient(config)
const sendEip712T = async() => {
const request = {
chainId: defChain.id,
account: address,
to: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049',
maxFeePerGas: 250000000n,
maxPriorityFeePerGas: 0n,
value: 100000,
gas: 318614,
...paymasterParams
}
const hash = await sendEip712Transaction(walletClient, request)
console.log(hash)
}-
Ensure you have
bunandpnpminstalled. -
Download
eip712branch from https://github.com/eigerco/viem. -
Go to
viemdirectory and modifypackage.jsonfiles:
- in the main viem directory add following beneath
"type": "module":
"name": "viem_zksync",
"version": "0.0.1",
"main": "src/index.ts",- in
src/actionsreplace the content with:
{
"name": "viem_zksync_actions",
"type": "module"
}- in
src/chainsreplace the content with:
{
"name": "viem_zksync_chains",
"type": "module"
}-
Run
bun installandbun run build -
Run
bun linkin the main directory. Then run the same command insrc/actionsandsrc/chains -
Download
betabranch from https://github.com/wevm/wagmi -
Go to
wagmidirectory and runpnpm installand thenpnpm build -
Run
bun linkin the following directories:
-
packages/react -
packages/core -
packages/connectors
- Go to this projects directory and run
-
bun install -
./bunlink.sh
- Finally run
bun dev- this will start the app, and openhttp://localhost:5173/in the browser
Project uses testnet ZkSync chain. You will need to have a ZkSync testnet account and MetaMask installed to perform tests.