Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor the Java SDK #72

Merged
merged 6 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions content/sdk/00.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ These SDKs, available in various programming languages, streamline the process o

- **Scalability**: Massively reduced transaction fees and faster confirmation times compared to Ethereum.
- **Security**: Inherits security from the underlying Ethereum blockchain.
- **Enhanced User Experience**: Enables smoother and more cost-effective dApp interactions for users.
- **Paymaster Support**: Enables flexible transaction fee payment strategies:
- **Enhanced user experience**: Enables smoother and more cost-effective dApp interactions for users.
- **Paymaster support**: Enables flexible transaction fee payment strategies:
- Third-party services can cover fees for users, fostering wider adoption.
- Gasless transactions become possible, improving user experience.
- **Account Abstraction**:
- **Account abstraction**:
- Enhances security and privacy by separating user accounts from keys.
- Improves developer experience by simplifying account management and enabling features like multi-signature wallets
and on-chain governance.
Expand Down Expand Up @@ -82,7 +82,7 @@ Explore Nuxt built-in components for pages, layouts, head, and more.
---
title: Java
icon: i-heroicons-rectangle-group
to: /sdk/java/getting-started
to: /sdk/java/introduction/overview
---
Integrate ZKsync Era with Java for cost-effective transactions.
::
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Introduction
description: Overview of Web3Providers and their functions.
description: Overview of Web3Providers and their functions
tags: ["web3", "blockchain", "provider", "zksync"]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Providers
title: Provider
description: Web3Provider for ZKsync Python SDK
tags: ["web3", "blockchain", "provider", "zksync"]
---
Expand Down
80 changes: 0 additions & 80 deletions content/sdk/40.java/00.getting-started.md

This file was deleted.

45 changes: 45 additions & 0 deletions content/sdk/40.java/00.introduction/00.overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Overview
description: An introduction to zksync2-java and its features.
tags: ["zksync", "java", "sdk", "blockchain", "ethereum"]
---

The `zksync2-java` is a powerful tool designed for developers working with the Ethereum blockchain.

## What is `zksync2-java`?

The `zksync2-java` library is a Java SDK designed to facilitate interactions with the ZkSync Era network. It provides a
set of tools and methods that allow developers to:

- Connect to the ZkSync network using a Web3 provider.
- Estimate transaction fees and gas usage.
- Interact with smart contracts deployed on ZkSync.
- Retrieve detailed information about transactions, blocks, and accounts.
- Utilize ZkSync-specific functionalities such as L1 to L2 transactions, bridge contracts, and more.

## Key features

### Seamless integration with web3j

The `zksync2-java` library builds upon the `web3j` library, ensuring that developers familiar with Web3j can easily
transition to using ZkSync-specific features. It supports all the standard Web3j functionalities while adding
additional methods tailored to the ZkSync Era.

### ZkSync-specific methods

The library includes a variety of methods specific to ZkSync, such as:

- Estimating fees for transactions (`estimateFee`).
- Calculating gas usage for transactions (`estimateGas`, `estimateGasL1`).
- Retrieving account balances and block details.
- Managing transactions between Layer 1 (L1) and Layer 2 (L2).
- Accessing bridge contracts and batch details.

### Ease of use

The `zksync2-java` library is designed with simplicity in mind, offering straightforward APIs and
documentation to help developers get started quickly and efficiently.

::callout{icon="i-heroicons-light-bulb"}
To get started with Java, follow the [installation instructions](/sdk/java/introduction/installation) provided.
::
32 changes: 32 additions & 0 deletions content/sdk/40.java/00.introduction/01.why-java-sdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: Why zksync2-java
description: Benefits and Advantages of zksync2-java
tags: ["zksync", "java", "ethereum", "layer-2", "zero-knowledge rollups"]
---

Choosing the Java SDK for ZKSync opens up a plethora of opportunities for businesses and developers eager to explore
the next generation of blockchain applications.

Here are key reasons why `zksync2-java` is a valuable addition to your development toolkit:

### Seamless web3 integration

- **Built on web3j**: The library extends `web3j`, making it easy for developers familiar with Web3j to start using
ZkSync-specific features without a steep learning curve.
- **Standard and extended functionality**: It supports all standard Web3j functionalities while adding methods unique
to ZkSync Era, enabling more versatile blockchain interactions.

### ZkSync-specific enhancements

- **Layer 2 transactions**: Leverage the power of zk-rollups for low-cost, high-throughput transactions.
- **Advanced fee and gas estimation**: Precisely estimate transaction fees and gas usage with methods
like `estimateFee`, `estimateGas`, and `estimateGasL1`.
- **Comprehensive account and block management**: Retrieve detailed information about accounts, blocks, and
transactions on the ZkSync network.
- **Bridge contract access**: Easily interact with ZkSync Era bridge contracts for L1 to L2 operations.

### User-friendly design

- **Easy initialization**: Quickly set up your provider with minimal configuration.
- **Clear and concise API**: The library's API is designed for simplicity and ease of use, ensuring you can integrate
it into your projects with minimal effort.
46 changes: 46 additions & 0 deletions content/sdk/40.java/00.introduction/02.installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: Installation
description: How to install and set up zksync2-java for your project.
tags: ["zksync", "java", "sdk installation"]
---

Integrating the `zksync2-java` into your Java project equips you with the tools necessary to interact with the
ZKSync Layer-2 blockchain solution efficiently.

## Prerequisites

Before beginning the installation, make sure you have:

- **Java Development Kit (JDK)**: Java 8 or higher installed on your machine.
- **Maven or Gradle**: Depending on your project's build system, ensure Maven or Gradle is set up correctly.

::callout{icon="i-heroicons-light-bulb"}
Check out the [Java installation guide](https://www.java.com/en/download) for more information.
::

## Installation steps

### Maven setup
For projects using Maven, add the following dependency block to your `pom.xml` file to include the `zksync2-java` SDK:

```xml
<project>
...
<dependencies>
<dependency>
<groupId>io.zksync</groupId>
<artifactId>zksync2</artifactId>
<version>v0.2.0</version>
</dependency>
</dependencies>
</project>
```

### Gradle setup
For projects utilizing Gradle, add the dependency to your `build.gradle` file as follows:

```groovy
dependencies {
implementation "io.zksync:zksync2:v0.2.0"
}
```
55 changes: 55 additions & 0 deletions content/sdk/40.java/01.guides/00.getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: Getting Started
description: Getting started with zksync2-java
tag: ["zksync", "java", "blockchain development", "layer-2", "zero-knowledge rollups"]
---

This guide is designed to help you quickly get up and running with the SDK, enabling you to interact with the ZKSync
Era blockchain efficiently.

## Understanding key components

Before delving into code examples, it's useful to familiarize yourself with the primary objects provided by the SDK and
their responsibilities:

- **`ZkSync`**: This class provides the connection to the ZKSync Era blockchain. It allows you to query blockchain
states, such as account details, block or transaction information, and event logs. It also facilitates read-only
interactions with the blockchain through calls and enables writing to the blockchain by sending transactions.
- **`Wallet`**: This object encapsulates all operations that interact with a user account. It manages the account's
private key, which is used to sign various types of payloads, and offers straightforward methods for executing common
blockchain functions.

::callout{icon="i-heroicons-light-bulb"}
Ensure you have installed the `zksync2-java` SDK. If you still need to do so, please refer to
the [installation guide](/sdk/java/introduction/installation) for detailed instructions.
::

## Examples

Connect to the ZKsync Era network:

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

public class Main {
public static void main(String ...args) {
ZkSync zksync = ZkSync.build(new HttpService("http://127.0.0.1:3050"));
}
}
```

Get the latest block number:

```java
BigInteger blockNumber = zksync.ethBlockNumber().send().getBlockNumber();
;
```

```java
ZksBlock block = zksync.zksGetBlockByHash("0xb472c070c9e121ba42702f6c322b7b266e287a4d8b5fa426ed265b105430c397", true).send().getBlock();
```

```java
ZkTransaction transaction = zksync.zksGetTransactionByHash("0x9af27afed9a4dd018c0625ea1368afb8ba08e4cfb69b3e76dfb8521c8a87ecfc").send().getResult();
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: ZKsync Era Features
description:
description: An overview of ZKsync Era features
tags: ["zksync", "java", "ethereum", "blockchain", "eip-712", "paymaster", "sdk"]
---

While ZKsync is mostly Web3-compatible, it has some differences compared to Ethereum. The major of those are:
Expand All @@ -11,10 +12,11 @@ While ZKsync is mostly Web3-compatible, it has some differences compared to Ethe

These require us to extend standard Ethereum transactions with new custom fields.
Such extended transactions are called EIP712 transactions since [EIP712](https://eips.ethereum.org/EIPS/eip-712)
is used to sign them. You can look at the internal structure of the EIP712 transactions
[here](https://docs.zksync.io/zk-stack/concepts/transaction-lifecycle#eip-712-0x71).
is used to sign them. You can look at the internal structure of the [EIP712 transactions](https://docs.zksync.io/zk-stack/concepts/transaction-lifecycle#eip-712-0x71).

::callout{icon="i-heroicons-light-bulb"}
This document will focus solely on how to pass these arguments to the SDK.
::

## Encoding paymaster params

Expand All @@ -24,4 +26,4 @@ the Matter Labs team endorses certain types of
that are processable by EOAs.

ZKsync SDK provides a utility method that can be used to get the correctly formed `paymasterParams` object:
[approvalBased](/sdk/java/paymaster-utils#encodeapprovalbased), [general](/sdk/java/paymaster-utils#encodegeneral).
[approvalBased](/sdk/java/api/utilities/paymaster-utils#encodeapprovalbased), [general](/sdk/java/api/utilities/paymaster-utils#encodegeneral).
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
title: Accounts | L1<->L2 Transactions
description:
title: L1<->L2 Transactions
description: Methods for handling transactions between L1 and L2 networks on ZKsync
tags: ["zksync", "l1", "l2", "transactions", "java", "sdk"]
---

This section explores the methods which allow the [account](/sdk/java/accounts) to send transactions
This section explores the methods which allow the [account](/sdk/java/api/accounts/wallet) to send transactions
among both L1 to L2 networks.

If you want some background on how L1<->L2 interaction works on ZKsync, go through the
Expand All @@ -12,25 +13,25 @@ If you want some background on how L1<->L2 interaction works on ZKsync, go throu
## Deposit

`Wallet` and `L1Signer` objects provide a deposit workflow.
For more information, please refer to the method specification [`Deposit`](/sdk/java/accounts#deposit).
For more information, please refer to the method specification [`Deposit`](/sdk/java/api/accounts/wallet#deposit).

For a complete example of how to execute the deposit workflow, take a look at the following:
[Deposit ETH and ERC20 token](https://github.com/zksync-sdk/zksync2-examples/blob/main/js/src/01_deposit.ts).

## Request execute

`Wallet` and `L1Signer` objects provide an option to request execution of L2 transaction from L1.
For more information, please refer to the method specification [`requestExecute`](/sdk/java/accounts#requestexecute).
For more information, please refer to the method specification [`requestExecute`](/sdk/java/api/accounts/wallet#requestexecute).

## Base cost

`Wallet` and `L1Signer` objects provide an option to calculate base cost for L2 transaction.
For more information, please refer to the method specification [`getBaseCost`](/sdk/java/accounts#getbasecost).
For more information, please refer to the method specification [`getBaseCost`](/sdk/java/api/accounts/wallet#getbasecost).

## Withdrawal

`Wallet` and `Signer` objects provide a withdrawal workflow.
For more information, please refer to the method specification [`Deposit`](/sdk/java/accounts#deposit).
For more information, please refer to the method specification [`Deposit`](/sdk/java/api/accounts/wallet#deposit).

For a complete example of how to execute the deposit workflow, take a look at the following:
[Withdraw ETH and ERC20 token](https://github.com/zksync-sdk/zksync2-examples/blob/main/js/src/04_withdraw.ts).
20 changes: 20 additions & 0 deletions content/sdk/40.java/02.api/00.providers/00.introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Introduction
description: Overview of Web3Providers and their functions.
tags: ["web3", "blockchain", "provider", "zksync"]
---

A Web3 Provider object provides application-layer access to underlying blockchain networks. It serves as a crucial
interface for interacting with various blockchain functionalities, enabling developers to connect, communicate, and
perform operations on the blockchain.

The [`zksync2-java`](https://github.com/zksync-sdk/zksync2-java) library supports provider methods from
the [`web3j`](https://docs.web3j.io/4.9.7/) library and supplies additional functionality tailored for the ZKsync Era network.

### Key features

- **Network connectivity:** Establishes connections to blockchain networks, allowing applications to interact with them.
- **Transaction management:** Facilitates the creation, sending, and tracking of transactions.
- **Gas estimation:** Provides estimations for the amount of gas required for transactions.
- **Account management:** Retrieves balances and transaction histories for accounts.
- **Contract interaction:** Enables interaction with smart contracts, including deploying and calling contract methods.
Loading
Loading