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: update go documentation structure #69

Merged
merged 11 commits into from
Jul 8, 2024
2 changes: 1 addition & 1 deletion content/sdk/00.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Integrate JS with ZKsync Era for secure transactions.
---
title: GO
icon: i-heroicons-cog
to: /sdk/go/getting-started
to: /sdk/go/introduction/overview
---
Integrate ZKsync GO SDK for ZKsync Era features.
::
Expand Down
24 changes: 24 additions & 0 deletions content/sdk/20.go/00.introduction/00.overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Overview
description: An introduction to `zksync2-go`
tags: ["zksync", "zksync2-go", "ethereum", "layer-2", "zero-knowledge rollups", "go library", "blockchain scalability", "crypto transactions"]
---

This guide will help you understand the fundamentals of `zksync2-go` and how to get started.

## What is `zksync2-go`?
`zksync2-go` is a Go library designed to interact with ZKsync, providing developers with the tools to integrate
ZKsync functionality into their Go applications. It simplifies the development process, offering easy-to-use
interfaces and comprehensive documentation.

## Features of `zksync2-go`

- **Scalability**: Leverages ZKsync's layer-2 technology to provide high transaction throughput.
- **Cost Efficiency**: Reduces transaction fees compared to on-chain transactions.
- **Security**: Ensures secure transactions through zero-knowledge proofs.
- **Ease of Use**: Provides an intuitive API for seamless integration into Go applications.
- **Interoperability**: Compatible with existing Ethereum tools and infrastructure.

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

Choosing the right tools and libraries for your blockchain project is crucial. `zksync2-go` offers a robust and
efficient solution for developers looking to leverage the benefits of ZKsync within their Go applications.

## Key advantages of `zksync2-go`

### 1. High performance and scalability

- **Layer-2 scaling**: Using ZKsync's layer-2 technology, `zksync2-go` significantly increases transaction
throughput, allowing your applications to handle more transactions per second.
- **Reduced latency**: Transactions are processed off-chain and then batched together for on-chain validation,
minimizing the delays associated with on-chain processing.

### 2. Cost efficiency

- **Lower fees**: Off-chain processing dramatically reduces transaction fees compared to traditional on-chain
transactions, making it cost-effective for developers and users.
- **Optimized resource usage**: Efficiently manages computational resources, reducing the overall cost of running
blockchain applications.

### 3. Security and reliability

- **Zero-knowledge proofs**: Ensures transaction integrity and privacy through zero-knowledge proofs, providing high security.
- **Trusted infrastructure**: Built on the reliable and proven ZKsync infrastructure, `zksync2-go` inherits its
security features and robustness.

### 4. Developer-friendly

- **Easy integration**: Provides a straightforward API that simplifies the integration of ZKsync functionality into Go applications.
- **Comprehensive documentation**: Offers detailed guides, examples, and API references to help developers start
quickly and efficiently.
- **Active Community and Support**: Benefit from an active community of developers and timely support from the
maintainers of `zksync2-go`.

### 5. Interoperability

- **Ethereum Compatibility**: Fully compatible with existing Ethereum tools and infrastructure, ensuring seamless
integration with other parts of the Ethereum ecosystem.
- **Future-Proof**: Designed to stay up-to-date with the latest advancements in the ZKsync protocol and the broader
blockchain landscape.
26 changes: 26 additions & 0 deletions content/sdk/20.go/00.introduction/02.installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Installation
description: How to install and set up zksync2-go for your project.
tags: ["zksync", "zksync2-go", "go", "sdk installation"]
---

Follow the steps below to set up the SDK in your development environment.

### Prerequisites

- Go: >=1.17 ([installation guide](https://go.dev/dl/))

### Installation steps

To install SDK for ZKsync Era, run the command below in your terminal.

```shell
go get github.com/zksync-sdk/zksync2-go
```

This command will download and install the `zksync2-go` package and its dependencies into your Go workspace.

### What next?

After completing these steps, `zksync2-go` will be installed and ready to use in your Go projects. You can now proceed
to integrate ZKsync functionalities into your applications by following the usage examples and API documentation.
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
---
title: Getting Started
description:
description: Getting Started with zksync2-go
tags: ["zksync", "zksync2-go", "go", "getting started"]
---

This is a short introduction to `zksync2-go` SDK, but covers many of the most common operations that developers require
and provides a starting point for those newer to ZKsync Era.
This guide provides an overview of the most common operations developers need to start using Go with ZKsync Era.

## Getting zksync2-go

### Prerequisites

- Go: >=1.17 ([installation guide](https://go.dev/dl/))

In order to install SDK for ZKsync Era, run the command below in your terminal.

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

## Overview
The `zksync2-go` SDK enables developers to interact with the ZKsync Era blockchain using the Go programming
language. While many standard SDK features work out of the box, some advanced functionalities like deploying smart
contracts or utilizing ZKsync-specific features (such as account abstraction) require additional fields beyond what
typical Ethereum transactions include.

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:
To start, it’s beneficial to understand the primary components of the SDK and their roles:

- `Client` 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.
- `Signer` 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.
- `Wallet` is a wrapper around `Client` and `Signer` that provides easy usage of the most common features.
- **Client**: Connects to the ZKsync Era blockchain, enabling you to query the blockchain state (e.g., account
details, blocks, and transactions), query event logs, or execute read-only code. It also facilitates sending
transactions to the blockchain.
- **Signer**: Manages operations that interact with an account, typically involving a private key used to sign various payloads.
- **Wallet**: A convenient wrapper around `Client` and `Signer`, providing easy access to the most commonly used features.

## Examples

Expand Down Expand Up @@ -108,5 +100,5 @@ Also, the following examples demonstrate how to:
7. [Deploy smart account](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/16_deploy_create_account.go).
8. [Use paymaster to pay fee with token](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/18_use_paymaster.go).

Full code for all examples is available [here](https://github.com/zksync-sdk/zksync2-examples/tree/main/go).
Full code for all examples is available in the [documentation](https://github.com/zksync-sdk/zksync2-examples/tree/main/go).
Examples are configured to interact with `ZKsync Era`, and `Sepolia` test networks.
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", "zksync2-go", "ethereum", "blockchain", "eip-712", "paymaster", "sdk"]
---

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

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

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

## EIP-712 Metadata

[`EIP712Meta`](/sdk/go/types/types#eip712meta) contains EIP-712 transaction metadata.
[`EIP712Meta`](/sdk/go/api/types#eip712meta) contains EIP-712 transaction metadata.
The following objects contain `EIP712Meta` and provides working with
EIP-712 transactions:

- [`types.CallMsg`](/sdk/go/types/types#callmsg)
- [`types.Transaction712`](/sdk/go/types/types#transaction712)
- [`accounts.CallMsg`](/sdk/go/types/types#callmsg)
- [`accounts.Transaction`](/sdk/go/types/types#transactiondetails)
- [`types.CallMsg`](/sdk/go/api/types#callmsg)
- [`types.Transaction712`](/sdk/go/api/types#transaction712)
- [`accounts.CallMsg`](/sdk/go/api/types#callmsg)
- [`accounts.Transaction`](/sdk/go/api/types#transactiondetails)

## Encoding paymaster params

Expand All @@ -35,7 +38,7 @@ 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:
[GetPaymasterParams](/sdk/go/paymaster-utils#getpaymasterparams).
[GetPaymasterParams](/sdk/go/api/utilities/paymaster-utils#getpaymasterparams).

## See in action

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
---
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", "go", "sdk"]
---

This section explores the methods which allow the [account](/sdk/go/accounts) 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
This section explores the methods which allow the [account](/sdk/go/api/accounts/introduction) to send transactions
among both L1 to
L2 networks. For background on how L1<->L2 interaction works on ZKsync, go through the
[introduction](https://docs.zksync.io/build/developer-reference/l1-l2-interoperability).

Full examples of actions below are available on the [getting started](/sdk/go/getting-started) page.
::callout{icon="i-heroicons-light-bulb"}
Full examples of actions below are available on the [getting started](/sdk/go/guides/getting-started) page.
::

## Deposit

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

For a comprehensive example demonstrating the deposit workflow, refer to the following:

Expand All @@ -23,27 +26,27 @@ For a comprehensive example demonstrating the deposit workflow, refer to the fol
## Request execute

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

## Base cost

`WalletL1` and `Wallet` objects provide an option to calculate base cost for L2 transaction.
For more information, please refer to the method specification [`BaseCost`](/sdk/go/accounts#basecost).
For more information, please refer to the method specification [`BaseCost`](/sdk/go/api/accounts/walletl1#basecost).

## Claim failed deposit

`WalletL1` and `Wallet` objects provide a claim fail deposit workflow. For more information,
please refer to the method specification [`ClaimFailedDeposit`](/sdk/go/accounts#claimfaileddeposit).
please refer to the method specification [`ClaimFailedDeposit`](/sdk/go/api/accounts/walletl1#claimfaileddeposit).

## Finalize withdraw

`WalletL1` and `Wallet` objects provide a finalize withdraw workflow. For more information,
please refer to the method specification [`FinalizeWithdraw`](/sdk/go/accounts#finalizewithdraw).
please refer to the method specification [`FinalizeWithdraw`](/sdk/go/api/accounts/introduction#finalizewithdraw).

## Withdrawal

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

For a complete example of how to execute the deposit workflow, take a look at the following:

Expand Down
36 changes: 36 additions & 0 deletions content/sdk/20.go/02.api/00.clients/00.introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Introduction
description: Overview of the Client component in the ZKsync Era
tags: ["zksync", "client", "go", "sdk"]
---

The `Client` is a critical component that enables interaction with the ZKsync Era. It serves as a wrapper around the
ZKsync Era RPC API and supports `ethclient.Client` from the `geth` library, along with additional methods specific to
ZKsync Era.

::callout{icon="i-heroicons-information-circle" color="blue"}
Since the `geth` library has the concept of a `Client`, not a `Provider`, the Go SDK for ZKsync Era also adopts the
concept of a `Client`, as opposed to using a Provider like in other ZKsync Era SDKs.
::

In code, the `Client` interface is composed of two main interfaces:

### `EthereumClient`

This interface provides Ethereum RPC methods on the ZKsync Era node, prefixed with `eth_`. It includes the same
methods as `ethclient.Client` from the `geth` library, ensuring compatibility with existing Ethereum tools and
workflows. Additionally, it has extra methods capable of handling EIP-712 transactions, which are essential for the
unique features of the ZKsync Era. The `EthereumClient` interface is designed to be compatible with
the `bind.ContractBackend` interface from `geth`, which enables support for smart contracts generated using
the `abigen` tool.

### `ZkSyncEraClient`

This interface provides the API methods specific to ZKsync Era, prefixed with `zks_`. These methods facilitate the
use of ZKsync Era’s unique features, such as account abstraction, custom fee systems, and other layer-2
functionalities. The `ZkSyncEraClient` interface ensures that developers can leverage all the capabilities of the
ZKsync Era blockchain efficiently.

::callout{icon="i-heroicons-light-bulb"}
These interfaces are designed to make the SDK flexible and extensible.
::
Loading
Loading