zkSync Era∎

❗️

zkSync Era is still in alpha.

zkSync Era nodes are still in alpha and subject to further updates. You may experience downtime.

If you notice discrepancies from the main API, report directly to Matter Labs.

🚧

Current API limitations

zkSync Era currently supports most of the wide-known JSON-RPC methods.

Interaction tools

MetaMask

On node access details, click Add to MetaMask.

Development tools

Hardhat

Configure Hardhat to deploy contracts and interact through your zkSync Era nodes.

  1. Install Hardhat and create a project.
    yarn add -D typescript ts-node ethers@^5.7.2 zksync-web3 hardhat @matterlabs/hardhat-zksync-solc @matterlabs/hardhat-zksync-deploy @matterlabs/zksync-contracts @openzeppelin/contracts @matterlabs/hardhat-zksync-verify @nomicfoundation/hardhat-verify dotenv
    
  2. Install the dotenv package to securely load your sensitive variables from a .env file
  3. Create a new environment in hardhat.config.ts:
import { HardhatUserConfig } from "hardhat/config";
require("dotenv").config();

import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-verify";

const config: HardhatUserConfig = {
  zksolc: {
    version: "1.3.13", // Use latest available
    compilerSource: "binary",
    settings: {},
  },
  defaultNetwork: "zkSyncTestnet",
  networks: {
    hardhat: {
      zksync: true,
    },
    zkSyncTestnet: {
      url: process.env.ZKSYNC_TESTNET_CHAINSTACK,
      ethNetwork: "goerli",
      zksync: true,
      verifyURL:
        "https://zksync2-testnet-explorer.zksync.dev/contract_verification",
    },
  },
  solidity: {
    version: "0.8.17",
  },
};

export default config;

πŸ“˜

Follow the tutorial for a better understanding: zkSync Era∎: Develop a custom paymaster contract

web3.js

Build DApps using web3.js and zkSync Era nodes deployed with Chainstack.

  1. Install web3.js.
  2. Connect over HTTP or WebSocket.

HTTPS

Use the HttpProvider object to connect to your node HTTPS endpoint and get the latest block number:

const Web3 = require('web3');

const web3 = new Web3(new Web3.providers.HttpProvider('YOUR_CHAINSTACK_ENDPOINT'));

web3.eth.getBlockNumber().then(console.log);

where YOUR_CHAINSTACK_ENDPOINT is your node HTTPS endpoint protected either with the key or password.

WSS

Use the WebsocketProvider object to connect to your node WSS endpoint and get the latest block number:

const Web3 = require('web3');

const web3 = new Web3(new Web3.providers.WebsocketProvider('YOUR_CHAINSTACK_ENDPOINT'));

web3.eth.getBlockNumber().then(console.log);

where YOUR_CHAINSTACK_ENDPOINT is your node WSS endpoint protected either with the key or password.

web3.py

Build DApps using web3.py and zkSync Era nodes deployed with Chainstack.

  1. Install web3.py.
  2. Connect over HTTP or WebSocket. See also EVM node connection: HTTP vs WebSocket.

HTTPS

Use HTTPProvider to connect to your node endpoint and get the latest block number.

from web3 import Web3

web3 = Web3(Web3.HTTPProvider('YOUR_CHAINSTACK_ENDPOINT'))
print(web3.eth.block_number)
from web3 import Web3

web3 = Web3(Web3.HTTPProvider('https://%s:%s@%s'% ("USERNAME", "PASSWORD", "HOSTNAME")))
print(web3.eth.block_number)

where

  • YOUR_CHAINSTACK_ENDPOINT β€” your node HTTPS endpoint protected either with the key or password
  • HOSTNAME β€” your node HTTPS endpoint hostname
  • USERNAME β€” your node access username (for password-protected endpoints)
  • PASSWORD β€” your node access password (for password-protected endpoints)

WSS

Use the WebsocketProvider object to connect to your node WSS endpoint and get the latest block number.

from web3 import Web3

web3 = Web3(Web3.WebsocketProvider('YOUR_CHAINSTACK_ENDPOINT'))
print(web3.eth.block_number)
from web3 import Web3

web3 = Web3(Web3.WebsocketProvider('wss://%s:%s@%s'% ("USERNAME", "PASSWORD", "HOSTNAME")))
print(web3.eth.block_number)

where

  • YOUR_CHAINSTACK_ENDPOINT β€” your node WSS endpoint protected either with the key or password
  • HOSTNAME β€” your node WSS endpoint hostname
  • USERNAME β€” your node access username (for password-protected endpoints)
  • PASSWORD β€” your node access password (for password-protected endpoints)

See also WebSocket connection to an EVM node.

node.js

You can build a web app to query data using node.js and axios:

const axios = require("axios");

const payload = {
    jsonrpc: "2.0",
    id: 0,
    method: "eth_blockNumber",
    params: []

};

(async () => {
    const response = await axios.post(`YOUR_CHAINSTACK_ENDPOINT`, payload)
    console.log(response.data)
})();
  • YOUR_CHAINSTACK_ENDPOINT β€” your Chainstack node endpoint protected either with the key or password. See node access details.
  • query β€” your JSON-RPC query. In this case, to get the latest block number.

ethers.js

Build DApps using ethers.js and zkSync Era nodes deployed with Chainstack.

  1. Install ethers.js.
  2. Connect over HTTPS or WebSocket. See also EVM node connection: HTTP vs WebSocket.

HTTPS

Use the JsonRpcProvider object to connect to your node endpoint and get the balance of any address:

const ethers = require('ethers');
const NODE_URL = "YOUR_CHAINSTACK_ENDPOINT ";
const provider = new ethers.JsonRpcProvider(NODE_URL, NETWORK_ID);
const eth_getBalance = async () => {
    const balance = await provider.getBalance("0x439356Ad40D2f2961c99FFED4453f482AEC453Af");
    console.log(balance);
  };
eth_getBalance()

where

  • YOUR_CHAINSTACK_ENDPOINT β€” your node HTTPS endpoint protected either with the key or password
  • NETWORK_ID β€” zkSync Era network ID:
    • Mainnet: 324
    • Goerli Testnet:280

WebSocket

Use the WebSocketProvider object to connect to your node WSS endpoint and get the latest block number:

const ethers = require('ethers');
const NODE_URL = "YOUR_CHAINSTACK_ENDPOINT";
const provider = new ethers.WebSocketProvider(NODE_URL, NETWORK_ID);
const eth_getBalance = async () => {
    const balance = await provider.getBalance("0x439356Ad40D2f2961c99FFED4453f482AEC453Af");
    console.log(balance);
  };
eth_getBalance()

where

  • YOUR_CHAINSTACK_ENDPOINT β€” your node WSS endpoint protected either with the key or password
  • NETWORK_ID β€” zkSync Era network ID:
    • Mainnet: 324
    • Goerli Testnet:280

Remix IDE

To make Remix IDE interact with the network through a zkSync Era node deployed with Chainstack:

  1. Get MetaMask and set it to interact through a Chainstack node. See Interacting through MetaMask.
  2. In Remix IDE, navigate to the Deploy tab. Select Injected Provider - MetaMask in Environment.

This will engage MetaMask and make Remix IDE interact with the network through a Chainstack node.