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
bun
andpnpm
installed. -
Download
eip712
branch from https://github.com/eigerco/viem. -
Go to
viem
directory and modifypackage.json
files:
- in the main viem directory add following beneath
"type": "module"
:
"name": "viem_zksync",
"version": "0.0.1",
"main": "src/index.ts",
- in
src/actions
replace the content with:
{
"name": "viem_zksync_actions",
"type": "module"
}
- in
src/chains
replace the content with:
{
"name": "viem_zksync_chains",
"type": "module"
}
-
Run
bun install
andbun run build
-
Run
bun link
in the main directory. Then run the same command insrc/actions
andsrc/chains
-
Download
beta
branch from https://github.com/wevm/wagmi -
Go to
wagmi
directory and runpnpm install
and thenpnpm build
-
Run
bun link
in 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.