The @zkchainhub/chain-providers
package provides wrappers of the Viem
library to interact with EVM-based blockchains and ZK chains of the ZKsync ecosystem.
- Ensure you have
node >= 20.0.0
andpnpm >= 9.5.0
installed.
$ pnpm install
To build the monorepo packages, run:
$ pnpm build
# unit tests
$ pnpm run test
# test coverage
$ pnpm run test:cov
You can import the package in your TypeScript or JavaScript files as follows:
import { EvmProvider } from "@zkchainhub/chain-providers";
// EVM-provider
const rpcUrls = [...]; //non-empty
const chain = mainnet; // from viem/chains
const evmProvider = new EvmProvider(rpcUrls, chain, logger);
const gasPrice = await evmProvider.getGasPrice();
const result = await evmProvider.readContract(address, abi, "myfunction", [arg1, arg2]);
// ZK-chain provider
const zkChainProvider = new ZKChainProvider(rpcUrls, chain, logger);
const l2Tps = await zkChainProvider.tps();
Available methods
getMulticall3Address()
getBalance(address: Address)
getBlockNumber()
getBlockByNumber(blockNumber: number)
getGasPrice()
estimateGas(args: EstimateGasParameters<typeof this.chain>)
getStorageAt(address: Address, slot: number | Hex)
readContract(contractAddress: Address, abi: TAbi functionName: TFunctionName, args?: TArgs)
batchRequest(abi: AbiWithConstructor,bytecode: Hex, args: ContractConstructorArgs<typeof abi>, constructorReturnParams: ReturnType)
multicall(args: MulticallParameters<contracts, allowFailure>)
Available methods
getL1BatchDetails(batchNumber: number)
getL1BatchNumber()
avgBlockTime(range: number = 1000)
tps()
For more details on both providers, refer to their implementations.