Skip to content

Commit 383b1de

Browse files
feat: refactor the Java SDK (#72)
* feat: refactor the Java SDK * fix: remove redundancy * fix: missing content * fix: update links * fix: minor update
1 parent d9e2aae commit 383b1de

File tree

20 files changed

+297
-133
lines changed

20 files changed

+297
-133
lines changed

content/sdk/00.index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ These SDKs, available in various programming languages, streamline the process o
3434

3535
- **Scalability**: Massively reduced transaction fees and faster confirmation times compared to Ethereum.
3636
- **Security**: Inherits security from the underlying Ethereum blockchain.
37-
- **Enhanced User Experience**: Enables smoother and more cost-effective dApp interactions for users.
38-
- **Paymaster Support**: Enables flexible transaction fee payment strategies:
37+
- **Enhanced user experience**: Enables smoother and more cost-effective dApp interactions for users.
38+
- **Paymaster support**: Enables flexible transaction fee payment strategies:
3939
- Third-party services can cover fees for users, fostering wider adoption.
4040
- Gasless transactions become possible, improving user experience.
41-
- **Account Abstraction**:
41+
- **Account abstraction**:
4242
- Enhances security and privacy by separating user accounts from keys.
4343
- Improves developer experience by simplifying account management and enabling features like multi-signature wallets
4444
and on-chain governance.
@@ -82,7 +82,7 @@ Explore Nuxt built-in components for pages, layouts, head, and more.
8282
---
8383
title: Java
8484
icon: i-heroicons-rectangle-group
85-
to: /sdk/java/getting-started
85+
to: /sdk/java/introduction/overview
8686
---
8787
Integrate ZKsync Era with Java for cost-effective transactions.
8888
::

content/sdk/30.python/02.api/00.providers/00.introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Introduction
3-
description: Overview of Web3Providers and their functions.
3+
description: Overview of Web3Providers and their functions
44
tags: ["web3", "blockchain", "provider", "zksync"]
55
---
66

content/sdk/30.python/02.api/00.providers/01.providers.md renamed to content/sdk/30.python/02.api/00.providers/01.provider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Providers
2+
title: Provider
33
description: Web3Provider for ZKsync Python SDK
44
tags: ["web3", "blockchain", "provider", "zksync"]
55
---

content/sdk/40.java/00.getting-started.md

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Overview
3+
description: An introduction to zksync2-java and its features.
4+
tags: ["zksync", "java", "sdk", "blockchain", "ethereum"]
5+
---
6+
7+
The `zksync2-java` is a powerful tool designed for developers working with the Ethereum blockchain.
8+
9+
## What is `zksync2-java`?
10+
11+
The `zksync2-java` library is a Java SDK designed to facilitate interactions with the ZkSync Era network. It provides a
12+
set of tools and methods that allow developers to:
13+
14+
- Connect to the ZkSync network using a Web3 provider.
15+
- Estimate transaction fees and gas usage.
16+
- Interact with smart contracts deployed on ZkSync.
17+
- Retrieve detailed information about transactions, blocks, and accounts.
18+
- Utilize ZkSync-specific functionalities such as L1 to L2 transactions, bridge contracts, and more.
19+
20+
## Key features
21+
22+
### Seamless integration with web3j
23+
24+
The `zksync2-java` library builds upon the `web3j` library, ensuring that developers familiar with Web3j can easily
25+
transition to using ZkSync-specific features. It supports all the standard Web3j functionalities while adding
26+
additional methods tailored to the ZkSync Era.
27+
28+
### ZkSync-specific methods
29+
30+
The library includes a variety of methods specific to ZkSync, such as:
31+
32+
- Estimating fees for transactions (`estimateFee`).
33+
- Calculating gas usage for transactions (`estimateGas`, `estimateGasL1`).
34+
- Retrieving account balances and block details.
35+
- Managing transactions between Layer 1 (L1) and Layer 2 (L2).
36+
- Accessing bridge contracts and batch details.
37+
38+
### Ease of use
39+
40+
The `zksync2-java` library is designed with simplicity in mind, offering straightforward APIs and
41+
documentation to help developers get started quickly and efficiently.
42+
43+
::callout{icon="i-heroicons-light-bulb"}
44+
To get started with Java, follow the [installation instructions](/sdk/java/introduction/installation) provided.
45+
::
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Why zksync2-java
3+
description: Benefits and Advantages of zksync2-java
4+
tags: ["zksync", "java", "ethereum", "layer-2", "zero-knowledge rollups"]
5+
---
6+
7+
Choosing the Java SDK for ZKSync opens up a plethora of opportunities for businesses and developers eager to explore
8+
the next generation of blockchain applications.
9+
10+
Here are key reasons why `zksync2-java` is a valuable addition to your development toolkit:
11+
12+
### Seamless web3 integration
13+
14+
- **Built on web3j**: The library extends `web3j`, making it easy for developers familiar with Web3j to start using
15+
ZkSync-specific features without a steep learning curve.
16+
- **Standard and extended functionality**: It supports all standard Web3j functionalities while adding methods unique
17+
to ZkSync Era, enabling more versatile blockchain interactions.
18+
19+
### ZkSync-specific enhancements
20+
21+
- **Layer 2 transactions**: Leverage the power of zk-rollups for low-cost, high-throughput transactions.
22+
- **Advanced fee and gas estimation**: Precisely estimate transaction fees and gas usage with methods
23+
like `estimateFee`, `estimateGas`, and `estimateGasL1`.
24+
- **Comprehensive account and block management**: Retrieve detailed information about accounts, blocks, and
25+
transactions on the ZkSync network.
26+
- **Bridge contract access**: Easily interact with ZkSync Era bridge contracts for L1 to L2 operations.
27+
28+
### User-friendly design
29+
30+
- **Easy initialization**: Quickly set up your provider with minimal configuration.
31+
- **Clear and concise API**: The library's API is designed for simplicity and ease of use, ensuring you can integrate
32+
it into your projects with minimal effort.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Installation
3+
description: How to install and set up zksync2-java for your project.
4+
tags: ["zksync", "java", "sdk installation"]
5+
---
6+
7+
Integrating the `zksync2-java` into your Java project equips you with the tools necessary to interact with the
8+
ZKSync Layer-2 blockchain solution efficiently.
9+
10+
## Prerequisites
11+
12+
Before beginning the installation, make sure you have:
13+
14+
- **Java Development Kit (JDK)**: Java 8 or higher installed on your machine.
15+
- **Maven or Gradle**: Depending on your project's build system, ensure Maven or Gradle is set up correctly.
16+
17+
::callout{icon="i-heroicons-light-bulb"}
18+
Check out the [Java installation guide](https://www.java.com/en/download) for more information.
19+
::
20+
21+
## Installation steps
22+
23+
### Maven setup
24+
For projects using Maven, add the following dependency block to your `pom.xml` file to include the `zksync2-java` SDK:
25+
26+
```xml
27+
<project>
28+
...
29+
<dependencies>
30+
<dependency>
31+
<groupId>io.zksync</groupId>
32+
<artifactId>zksync2</artifactId>
33+
<version>v0.2.0</version>
34+
</dependency>
35+
</dependencies>
36+
</project>
37+
```
38+
39+
### Gradle setup
40+
For projects utilizing Gradle, add the dependency to your `build.gradle` file as follows:
41+
42+
```groovy
43+
dependencies {
44+
implementation "io.zksync:zksync2:v0.2.0"
45+
}
46+
```
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: Getting Started
3+
description: Getting started with zksync2-java
4+
tag: ["zksync", "java", "blockchain development", "layer-2", "zero-knowledge rollups"]
5+
---
6+
7+
This guide is designed to help you quickly get up and running with the SDK, enabling you to interact with the ZKSync
8+
Era blockchain efficiently.
9+
10+
## Understanding key components
11+
12+
Before delving into code examples, it's useful to familiarize yourself with the primary objects provided by the SDK and
13+
their responsibilities:
14+
15+
- **`ZkSync`**: This class provides the connection to the ZKSync Era blockchain. It allows you to query blockchain
16+
states, such as account details, block or transaction information, and event logs. It also facilitates read-only
17+
interactions with the blockchain through calls and enables writing to the blockchain by sending transactions.
18+
- **`Wallet`**: This object encapsulates all operations that interact with a user account. It manages the account's
19+
private key, which is used to sign various types of payloads, and offers straightforward methods for executing common
20+
blockchain functions.
21+
22+
::callout{icon="i-heroicons-light-bulb"}
23+
Ensure you have installed the `zksync2-java` SDK. If you still need to do so, please refer to
24+
the [installation guide](/sdk/java/introduction/installation) for detailed instructions.
25+
::
26+
27+
## Examples
28+
29+
Connect to the ZKsync Era network:
30+
31+
```java
32+
import io.zksync.protocol.ZkSync;
33+
import org.web3j.protocol.http.HttpService;
34+
35+
public class Main {
36+
public static void main(String ...args) {
37+
ZkSync zksync = ZkSync.build(new HttpService("http://127.0.0.1:3050"));
38+
}
39+
}
40+
```
41+
42+
Get the latest block number:
43+
44+
```java
45+
BigInteger blockNumber = zksync.ethBlockNumber().send().getBlockNumber();
46+
;
47+
```
48+
49+
```java
50+
ZksBlock block = zksync.zksGetBlockByHash("0xb472c070c9e121ba42702f6c322b7b266e287a4d8b5fa426ed265b105430c397", true).send().getBlock();
51+
```
52+
53+
```java
54+
ZkTransaction transaction = zksync.zksGetTransactionByHash("0x9af27afed9a4dd018c0625ea1368afb8ba08e4cfb69b3e76dfb8521c8a87ecfc").send().getResult();
55+
```

content/sdk/40.java/01.features.md renamed to content/sdk/40.java/01.guides/01.features.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: ZKsync Era Features
3-
description:
3+
description: An overview of ZKsync Era features
4+
tags: ["zksync", "java", "ethereum", "blockchain", "eip-712", "paymaster", "sdk"]
45
---
56

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

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

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

1921
## Encoding paymaster params
2022

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

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

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

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

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

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

2021
## Request execute
2122

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

2526
## Base cost
2627

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

3031
## Withdrawal
3132

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

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

0 commit comments

Comments
 (0)