Getting Started

This is a short introduction to zksync2-java SDK, but covers many of the most common operations that developers require and provides a starting point for those newer to ZKsync Era.

Getting zksync-ethers


For connecting ZkSync2 library just add the following dependency to your build file.

Maven pom.xml


Gradle build.gradle

dependencies {
    implementation "io.zksync:zksync2:v0.2.0"


While most of the existing SDKs should work out of the box, deploying smart contracts or using unique ZKsync features, like account abstraction, requires providing additional fields to those that Ethereum transactions have by default.

To begin, it is useful to have a basic understanding of the types of objects available and what they are responsible for, at a high level:

  • ZkSync provides connection to the ZKsync Era blockchain, which allows querying the blockchain state, such as account, block or transaction details, querying event logs or evaluating read-only code using call. Additionally, the client facilitates writing to the blockchain by sending transactions.
  • Wallet wraps all operations that interact with an account. An account generally has a private key, which can be used to sign a variety of types of payloads. It provides easy usage of the most common features.


Connect to the ZKsync Era network:

import io.zksync.protocol.ZkSync;
import org.web3j.protocol.http.HttpService;

public class Main {
    public static void main(String ...args) {
        ZkSync zksync = HttpService(""));

Get the latest block number:

BigInteger blockNumber = zksync.ethBlockNumber().send().getBlockNumber();
ZksBlock block = zksync.zksGetBlockByHash("0xb472c070c9e121ba42702f6c322b7b266e287a4d8b5fa426ed265b105430c397", true).send().getBlock();
ZkTransaction transaction = zksync.zksGetTransactionByHash("0x9af27afed9a4dd018c0625ea1368afb8ba08e4cfb69b3e76dfb8521c8a87ecfc").send().getResult();

Made with ❤️ by the ZKsync Community