Web3JS

Getting Started

How to install and initialize the Web3.js plugin for ZKsync

Follow these steps to get started with the Web3.js plugin for ZKsync.

Installation

Use a package manager like npm to install Web3.js and the Web3.js plugin for ZKsync.

npm install web3 web3-plugin-zksync

Register the plugin

To use the Web3.js plugin for ZKsync, register it with a Web3 instance.

import { Web3 } from "web3";
import { ZKsyncPlugin } from "web3-plugin-zksync";

async function main() {
  const web3: Web3 = new Web3(/* optional L1 provider */);
  web3.registerPlugin(new ZKsyncPlugin("https://sepolia.era.zksync.dev"));
  const zksync: ZKsyncPlugin = web3.ZKsync;

  console.log("L2 contract addresses:", await zksync.ContractsAddresses);
}

main()
  .then(() => console.log("✅ Script executed successfully"))
  .catch((error) => console.error(`❌ Error executing script: ${error}`));

Made with ❤️ by the ZKsync Community