From bcc7d35e582793a7fda26744e35e68c809011787 Mon Sep 17 00:00:00 2001 From: Ngozi-Txfusion Date: Sat, 6 Jul 2024 17:29:39 +0100 Subject: [PATCH 1/9] feat: update go documentation structure --- content/sdk/00.index.md | 2 +- .../sdk/20.go/00.introduction/00.overview.md | 24 + .../00.introduction/01.why-zksync2-go.md | 45 + .../20.go/00.introduction/02.installation.md | 26 + .../{ => 01.guides}/00.getting-started.md | 46 +- .../01.features.md} | 9 +- .../02.accounts-l1-l2.md} | 14 +- .../02.api/00.clients/00.introduction.md | 36 + .../00.clients/01.baseclient.md} | 31 +- .../00.clients/02.types.md} | 9 +- .../02.api/01.accounts/00.introduction.md | 55 + .../20.go/02.api/01.accounts/01.basesigner.md | 76 + .../02.api/01.accounts/02.basedeployer.md | 165 ++ .../sdk/20.go/02.api/01.accounts/03.wallet.md | 214 ++ .../20.go/02.api/01.accounts/04.walletl1.md | 1002 +++++++ .../20.go/02.api/01.accounts/05.walletl2.md | 523 ++++ .../02.api/01.accounts/06.smartaccount.md | 57 + .../00.newecdsasmartaccount.md | 34 + .../01.newmultisigecdsasmartaccount.md | 459 +++ .../01.accounts}/08.smart-account-utils.md | 7 +- .../01.accounts/09.types.md} | 8 +- .../02.eip712/00.eip712.md} | 7 +- .../03.contracts/00.contracts.md} | 3 +- .../04.utilities/00.utils.md} | 8 +- .../04.utilities/01.paymaster-utils.md} | 6 +- .../{types => 02.api/05.types}/00.intro.md | 0 .../{types => 02.api/05.types}/04.types.md | 0 content/sdk/20.go/02.api/_dir.yml | 1 + content/sdk/20.go/04.accounts.md | 2524 ----------------- 29 files changed, 2794 insertions(+), 2597 deletions(-) create mode 100644 content/sdk/20.go/00.introduction/00.overview.md create mode 100644 content/sdk/20.go/00.introduction/01.why-zksync2-go.md create mode 100644 content/sdk/20.go/00.introduction/02.installation.md rename content/sdk/20.go/{ => 01.guides}/00.getting-started.md (65%) rename content/sdk/20.go/{02.features.md => 01.guides/01.features.md} (92%) rename content/sdk/20.go/{05.accounts-l1-l2.md => 01.guides/02.accounts-l1-l2.md} (84%) create mode 100644 content/sdk/20.go/02.api/00.clients/00.introduction.md rename content/sdk/20.go/{03.clients.md => 02.api/00.clients/01.baseclient.md} (96%) rename content/sdk/20.go/{types/02.clients.md => 02.api/00.clients/02.types.md} (86%) create mode 100644 content/sdk/20.go/02.api/01.accounts/00.introduction.md create mode 100644 content/sdk/20.go/02.api/01.accounts/01.basesigner.md create mode 100644 content/sdk/20.go/02.api/01.accounts/02.basedeployer.md create mode 100644 content/sdk/20.go/02.api/01.accounts/03.wallet.md create mode 100644 content/sdk/20.go/02.api/01.accounts/04.walletl1.md create mode 100644 content/sdk/20.go/02.api/01.accounts/05.walletl2.md create mode 100644 content/sdk/20.go/02.api/01.accounts/06.smartaccount.md create mode 100644 content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md create mode 100644 content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md rename content/sdk/20.go/{ => 02.api/01.accounts}/08.smart-account-utils.md (96%) rename content/sdk/20.go/{types/01.accounts.md => 02.api/01.accounts/09.types.md} (98%) rename content/sdk/20.go/{types/03.eip712.md => 02.api/02.eip712/00.eip712.md} (58%) rename content/sdk/20.go/{06.contracts.md => 02.api/03.contracts/00.contracts.md} (90%) rename content/sdk/20.go/{06.utils.md => 02.api/04.utilities/00.utils.md} (96%) rename content/sdk/20.go/{07.paymaster-utils.md => 02.api/04.utilities/01.paymaster-utils.md} (87%) rename content/sdk/20.go/{types => 02.api/05.types}/00.intro.md (100%) rename content/sdk/20.go/{types => 02.api/05.types}/04.types.md (100%) create mode 100644 content/sdk/20.go/02.api/_dir.yml delete mode 100644 content/sdk/20.go/04.accounts.md diff --git a/content/sdk/00.index.md b/content/sdk/00.index.md index 700cde22..2587a20e 100644 --- a/content/sdk/00.index.md +++ b/content/sdk/00.index.md @@ -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. :: diff --git a/content/sdk/20.go/00.introduction/00.overview.md b/content/sdk/20.go/00.introduction/00.overview.md new file mode 100644 index 00000000..4dc41cdf --- /dev/null +++ b/content/sdk/20.go/00.introduction/00.overview.md @@ -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. +:: diff --git a/content/sdk/20.go/00.introduction/01.why-zksync2-go.md b/content/sdk/20.go/00.introduction/01.why-zksync2-go.md new file mode 100644 index 00000000..cbe12581 --- /dev/null +++ b/content/sdk/20.go/00.introduction/01.why-zksync2-go.md @@ -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. diff --git a/content/sdk/20.go/00.introduction/02.installation.md b/content/sdk/20.go/00.introduction/02.installation.md new file mode 100644 index 00000000..6a0c0de0 --- /dev/null +++ b/content/sdk/20.go/00.introduction/02.installation.md @@ -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. diff --git a/content/sdk/20.go/00.getting-started.md b/content/sdk/20.go/01.guides/00.getting-started.md similarity index 65% rename from content/sdk/20.go/00.getting-started.md rename to content/sdk/20.go/01.guides/00.getting-started.md index 3382ba7a..684a4d99 100644 --- a/content/sdk/20.go/00.getting-started.md +++ b/content/sdk/20.go/01.guides/00.getting-started.md @@ -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 - -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: - -- `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. +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. + +To start, it’s beneficial to understand the primary components of the SDK and their roles: + +- **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 diff --git a/content/sdk/20.go/02.features.md b/content/sdk/20.go/01.guides/01.features.md similarity index 92% rename from content/sdk/20.go/02.features.md rename to content/sdk/20.go/01.guides/01.features.md index 11bc88b7..1dcb6f97 100644 --- a/content/sdk/20.go/02.features.md +++ b/content/sdk/20.go/01.guides/01.features.md @@ -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: @@ -11,10 +12,12 @@ 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 diff --git a/content/sdk/20.go/05.accounts-l1-l2.md b/content/sdk/20.go/01.guides/02.accounts-l1-l2.md similarity index 84% rename from content/sdk/20.go/05.accounts-l1-l2.md rename to content/sdk/20.go/01.guides/02.accounts-l1-l2.md index 92015f8a..2f179cdc 100644 --- a/content/sdk/20.go/05.accounts-l1-l2.md +++ b/content/sdk/20.go/01.guides/02.accounts-l1-l2.md @@ -1,14 +1,16 @@ --- -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/accounts) 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 diff --git a/content/sdk/20.go/02.api/00.clients/00.introduction.md b/content/sdk/20.go/02.api/00.clients/00.introduction.md new file mode 100644 index 00000000..577f9383 --- /dev/null +++ b/content/sdk/20.go/02.api/00.clients/00.introduction.md @@ -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. +:: diff --git a/content/sdk/20.go/03.clients.md b/content/sdk/20.go/02.api/00.clients/01.baseclient.md similarity index 96% rename from content/sdk/20.go/03.clients.md rename to content/sdk/20.go/02.api/00.clients/01.baseclient.md index adf3d929..fcbc6f24 100644 --- a/content/sdk/20.go/03.clients.md +++ b/content/sdk/20.go/02.api/00.clients/01.baseclient.md @@ -1,30 +1,13 @@ --- -title: Clients -description: +title: BaseClient +description: Primary implementation of ZKsync client +tags: ["zksync", "client", "baseclient", "go", "sdk"] --- -::callout{icon="i-heroicons-information-circle" color="blue"} -Since the `geth` library has the concept of a `Client`, not a `Provider`, that's why the Go SDK for ZKsync Era -also adopts the concept of a `Client`, as opposed to using a Provider like in the other ZKsync Era SDKs. -:: - -`Client` is a wrapper around the ZKsync Era RPC API, which supports `ethclient.Client` from the `geth` library -and additional methods specific to ZKsync Era. - -`Client` in code represents the interface that is composed of the following two interfaces: - -- `EthereumClient` provides Ethereum RPC methods on the ZKsync Era node, those with the `eth_` prefix. - This interface contains the same methods as `ethclient.Client` from the `geth` library. Additionally, - it has extra methods capable of working with EIP-712 transactions. It is designed to be compatible with - the `bind.ContractBackend` interface from `geth`, enabling support for smart contracts generated using the - `abigen` tool. -- `ZkSyncEraClient` provides the API for ZKsync Era features and specific RPC methods, those with the `zks_` prefix. - -These interfaces are separated to make the SDK more flexible and extensible. - -## `BaseClient` - -`BaseClient` implements the `Client` interface and provides interaction with ZKsync Era RPC API. +The `BaseClient` is the primary implementation of the `Client` interface. It facilitates +interaction with the ZKsync Era RPC API, providing the necessary methods to perform various blockchain +operations. The `BaseClient` leverages both Ethereum RPC methods and ZKsync-specific functionalities to offer a +comprehensive toolset for developers. ### `Init` diff --git a/content/sdk/20.go/types/02.clients.md b/content/sdk/20.go/02.api/00.clients/02.types.md similarity index 86% rename from content/sdk/20.go/types/02.clients.md rename to content/sdk/20.go/02.api/00.clients/02.types.md index e089183a..0378ba11 100644 --- a/content/sdk/20.go/types/02.clients.md +++ b/content/sdk/20.go/02.api/00.clients/02.types.md @@ -1,8 +1,13 @@ --- -title: Clients Package -description: +title: Types +description: Primary types used in the ZKsync Era +tags: ["zksync", "types", "go", "sdk", "clients"] --- +The following section describes key types used in the ZKsync +Era. These types facilitate various blockchain operations, such as specifying block ranges, performing withdrawals, and +executing transfers. + ### `BlockRange` Represents a range of blocks with the starting and ending block numbers. diff --git a/content/sdk/20.go/02.api/01.accounts/00.introduction.md b/content/sdk/20.go/02.api/01.accounts/00.introduction.md new file mode 100644 index 00000000..6a4bdf29 --- /dev/null +++ b/content/sdk/20.go/02.api/01.accounts/00.introduction.md @@ -0,0 +1,55 @@ +--- +title: Introduction +description: Overview of the accounts package in ZKsync Era +tags: ["zksync", "accounts", "go", "sdk"] +--- + +The `accounts` package provides abstractions that wrap operations that interact with an account. An account typically +contains a private key, allowing it to sign various types of payloads. There are the following interfaces that +provide account operations for different purposes: + +- **Signer**: Provides support for signing EIP-712 transactions as well as other types of transactions supported by [`types.Signer`](https://pkg.go.dev/github.com/ethereum/go-ethereum@v1.12.0/core/types#Signer). +- **AdapterL1**: Associated with an account and provides common operations on the L1 network for the associated account. +- **AdapterL2**: Associated with an account and provides common operations on the L2 network for the associated account. +- **Deployer**: Associated with an account and provides deployment of smart contracts and smart accounts on the L2 +network for the associated account. +- **Adapter**: Consists of `AdapterL1`, `AdapterL2`, and `Deployer` interfaces. + +There are the following objects that provide account operations: + +### `BaseSigner` +Implements the `Signer` interface. The `BaseSigner` is responsible for signing various types of transactions, including +EIP-712 transactions. It abstracts the complexities involved in signing transactions, making it easier for developers +to handle secure and authenticated interactions with the blockchain. + +### `WalletL1` +Implements the `AdapterL1` interface. `WalletL1` is designed to manage and perform common operations on the Layer 1 +(L1) network. This includes sending transactions, checking balances, and interacting with smart contracts deployed on +the Ethereum mainnet. + +### `WalletL2` +Implements the `AdapterL2` interface. `WalletL2` facilitates operations on the Layer 2 (L2) network, specifically +tailored for ZKsync Era. It handles transactions that benefit from the scalability and low fees of L2 solutions, +providing a seamless way to interact with the L2 environment. + +### `BaseDeployer` +Implements the `Deployer` interface. The `BaseDeployer` provides functionalities for deploying smart contracts and +smart accounts on the L2 network. It simplifies the deployment process, ensuring that developers can easily and +efficiently deploy their applications on ZKsync Era. + +### `Wallet` +Implements the `Adapter` interface. The `Wallet` object combines the functionalities of `AdapterL1`, `AdapterL2`, +and `Deployer`, offering a comprehensive tool for managing accounts and performing operations across both L1 and L2 +networks. It is the recommended object for most use cases as it provides all necessary operations in one place. + +### `SmartAccount` +Provides enhanced support for account abstraction. The `SmartAccount` is designed to offer advanced account +management capabilities, supporting complex account structures and operations. + +#### `NewECDSASmartAccount` +Uses a single ECDSA key for signing payloads. This factory method creates a `SmartAccount` that leverages a single +ECDSA key, ensuring simple yet secure transaction signing. + +#### `NewMultisigECDSASmartAccount` +Uses multiple ECDSA keys for signing payloads. This method creates a `SmartAccount` that supports multisig +functionality, enhancing security by requiring multiple signatures for transaction approval. diff --git a/content/sdk/20.go/02.api/01.accounts/01.basesigner.md b/content/sdk/20.go/02.api/01.accounts/01.basesigner.md new file mode 100644 index 00000000..b6cdfc63 --- /dev/null +++ b/content/sdk/20.go/02.api/01.accounts/01.basesigner.md @@ -0,0 +1,76 @@ +--- +title: BaseSigner +description: Handles transaction signing for ZKsync +tags: ["zksync", "baseSigner", "signer", "go", "sdk"] +--- + +The `BaseSigner` class is designed to handle the creation and management of signing keys, allowing secure and +authenticated interactions with the ZKsync Era blockchain. + +### `Init` + +Creates a new instance of `BaseSigner` based on the provided mnemonic phrase. + +```go +func NewBaseSignerFromMnemonic(mnemonic string, chainId int64) (*BaseSigner, error) +``` + +Creates a new instance of `BaseSigner` based on the provided mnemonic phrase and account ID. + +```go +func NewBaseSignerFromMnemonicAndAccountId(mnemonic string, accountId uint32, chainId int64) (*BaseSigner, error) +``` + +Creates a new instance of BaseSigner based on the provided raw private key. + +```go +func NewBaseSignerFromRawPrivateKey(rawPk []byte, chainId int64) (*BaseSigner, error) +``` + +Creates an instance of Signer with a randomly generated private key. + +```go +func NewRandomBaseSigner(chainId int64) (*BaseSigner, error) +``` + +### `Address` + +Returns the address associated with the signer. + +```go +Address() common.Address +``` + +### `Domain` + +Returns the EIP-712 domain used for signing. + +```go +Domain() *eip712.Domain +``` + +### `PrivateKey` + +Returns the private key associated with the signer. + +```go +PrivateKey() *ecdsa.PrivateKey +``` + +Signs the given hash using the signer's private key and returns the signature. The hash should be the 32-byte hash +of the data to be signed. + +### `SignHash` + +```go +SignHash(msg []byte) ([]byte, error) +``` + +### `SignTypeData` + +Signs the given EIP-712 typed data using the signer's private key and returns the signature. The domain parameter +is the EIP-712 domain separator, and the data parameter is the EIP-712 typed data. + +```go +SignTypedData(d *eip712.Domain, data eip712.TypedData) ([]byte, error) +``` diff --git a/content/sdk/20.go/02.api/01.accounts/02.basedeployer.md b/content/sdk/20.go/02.api/01.accounts/02.basedeployer.md new file mode 100644 index 00000000..90bae551 --- /dev/null +++ b/content/sdk/20.go/02.api/01.accounts/02.basedeployer.md @@ -0,0 +1,165 @@ +--- +title: BaseDeployer +description: Deploys smart contracts and accounts +tags: ["zksync", "deployer", "smart contracts", "go", "sdk"] +--- + +The `BaseDeployer` facilitates the deployment of smart contracts and smart accounts on the ZKsync Era network. It +provides methods to deploy contracts using both the `CREATE` and `CREATE2` methods, ensuring flexibility and security in +contract deployment. + +### `Init` + +Creates an instance of `BaseDeployer` based on provided `AdapterL2`. + +```go +func NewBaseDeployer(adapter *AdapterL2) *BaseDeployer +``` + +### `Deploy` + +Deploys smart contract using CREATE2 method. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------- | ------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`Create2Transaction`](/sdk/go/types/accounts#create2transaction) | CREATE2 transaction parameters. | + +```go +Deploy(auth *TransactOpts, tx Create2Transaction) (common.Hash, error) +``` + +#### Example + +```go +bytecode, err := os.ReadFile("Storage.zbin") +if err != nil { + log.Panic(err) +} + +//Deploy smart contract +hash, err := wallet.Deploy(nil, accounts.Create2Transaction{Bytecode: bytecode}) +if err != nil { + panic(err) +} +fmt.Println("Transaction: ", hash) +``` + +### `DeployWithCreate` + +Deploys smart contract using CREATE method. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------------------- | ------------------------------ | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`CreateTransaction`](/sdk/go/types/accounts#createtransaction) | CREATE transaction parameters. | + +```go +DeployWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error) +``` + +#### Example + +```go +bytecode, err := os.ReadFile("Storage.zbin") +if err != nil { + log.Panic(err) +} + +//Deploy smart contract +hash, err := wallet.DeployWithCreate(nil, accounts.CreateTransaction{Bytecode: bytecode}) +if err != nil { + panic(err) +} +fmt.Println("Transaction: ", hash) +``` + +### `DeployAccount` + +Deploys smart account using CREATE2 method. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------- | ------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`Create2Transaction`](/sdk/go/types/accounts#create2transaction) | CREATE2 transaction parameters. | + +```go +DeployAccount(auth *TransactOpts, tx Create2Transaction) (common.Hash, error) +``` + +#### Example + +```go +# Crown token on testnet +TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") + +_, paymasterAbi, bytecode, err := utils.ReadStandardJson("Paymaster.json") +if err != nil { + log.Panic(err) +} + +// Encode paymaster constructor +constructor, err := paymasterAbi.Pack("", common.HexToAddress(TokenAddress)) +if err != nil { + log.Panic(err) +} + +// Deploy paymaster contract +hash, err := wallet.DeployAccount(nil, accounts.Create2Transaction{Bytecode: bytecode, Calldata: constructor}) +if err != nil { + log.Panic(err) +} +if err != nil { + log.Panic(err) +} +fmt.Println("Transaction: ", hash) + +``` + +### `DeployAccountWithCreate` + +Deploys smart account using CREATE method. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------------------- | ------------------------------ | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`CreateTransaction`](/sdk/go/types/accounts#createtransaction) | CREATE transaction parameters. | + +```go +DeployAccountWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error) +``` + +#### Example + +```go +# Crown token on testnet +TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") + +_, paymasterAbi, bytecode, err := utils.ReadStandardJson("Paymaster.json") +if err != nil { + log.Panic(err) +} + +constructor, err := paymasterAbi.Pack("", common.HexToAddress(TokenAddress)) +if err != nil { + log.Panic(err) +} + +// Deploy paymaster contract +hash, err := wallet.DeployAccountWithCreate(nil, accounts.CreateTransaction{ + Bytecode: bytecode, + Calldata: constructor, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Transaction: ", hash) +``` diff --git a/content/sdk/20.go/02.api/01.accounts/03.wallet.md b/content/sdk/20.go/02.api/01.accounts/03.wallet.md new file mode 100644 index 00000000..f62fc895 --- /dev/null +++ b/content/sdk/20.go/02.api/01.accounts/03.wallet.md @@ -0,0 +1,214 @@ +--- +title: Wallet +description: Unified interface for managing accounts +tags: ["zksync", "wallet", "account management", "go", "sdk"] +--- + +It contains the same functions +as [`WalletL1`](/sdk/go/api/accounts/walletl1), [`WalletL2`](/sdk/go/api/accounts/walletl2), and [`BaseDeployer`](/sdk/go/api/accounts/basedeployer) +since it implements the Adapter interface, and the usage of those methods is the same. + +### `Init` + +Creates an instance of `Wallet` associated with the account provided by the `rawPrivateKey`. The `clientL1` +parameters is optional; if not provided, only methods from `AdapterL2` and `Deployer` interfaces can be used, +as the rest of the functionalities require communication with the L1 network. A `Wallet` can be configured to +communicate with L1 networks by using and [`ConnectL1`](#connectl1) method. + +```go +func NewWallet(rawPrivateKey []byte, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) +``` + +Creates an instance of Wallet associated with the account provided by the signer. The `clientL2` and `clientL1` +parameters are optional; if not provided, only `SignTransaction`, `Address` and `Signer` methods can be used, +as the rest of the functionalities require communication with the network. A wallet that contains only a +signer can be configured to communicate with L2 and L1 networks by using [`Connect`](#connect) and +[`ConnectL1`](#connectl1), respectively. + +```go +func NewWalletFromSigner(signer Signer, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) +``` + +Creates a new instance of `Wallet` based on the provided mnemonic phrase. The `clientL2` and `clientL1` +parameters are optional, and can be configured with [`Connect`](#connect) and [`ConnectL1`](#connectl1), respectively. + +```go +func NewWalletFromMnemonic(mnemonic string, chainId int64, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) +``` + +Creates a new instance of `Wallet` based on the provided private key of the account and chain ID. +The `clientL2` and `clientL1` parameters are optional, and can be configured with [`Connect`](#connect) +and [`ConnectL1`](#connectl1), respectively. + +```go +func NewWalletFromRawPrivateKey(rawPk []byte, chainId int64, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) +``` + +Creates an instance of `Wallet` with a randomly generated account. The `clientL2` and `clientL1` parameters are +optional, and can be configured with [`Connect`](#connect) and [`ConnectL1`](#connectl1), respectively. + +```go +func NewRandomWallet(chainId int64, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) +``` + +#### Example + +```go +PrivateKey := os.Getenv("PRIVATE_KEY") +ZkSyncEraProvider := "https://sepolia.era.zksync.dev" +EthereumProvider := "https://rpc.ankr.com/eth_sepolia" + +client, err := clients.Dial(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +ethClient, err := ethclient.Dial(EthereumProvider) +if err != nil { + log.Panic(err) +} +defer ethClient.Close() + +wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, ethClient) +if err != nil { + log.Panic(err) +} + +chainID, err := client.ChainID(context.Background()) +if err != nil { + log.Panic(err) +} +wallet, err = accounts.NewRandomWallet(chainID.Int64(),nil,nil) +if err != nil { + log.Panic(err) +} +``` + +### `Connect` + +Returns a new instance of `Wallet` with the provided client for the L2 network. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ---------------------------- | ----------- | +| `client` | [`*clients.Client`](/sdk/go/clients) | L2 client. | + +```go +Connect(client *clients.Client) (*Wallet, error) +``` + +#### Example + +```go +PrivateKey := os.Getenv("PRIVATE_KEY") +ZkSyncEraProvider := "https://testnet.era.zksync.dev" + +client, err := clients.Dial(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +chainID, err := client.ChainID(context.Background()) +if err != nil { + log.Panic(err) +} + +wallet, err := accounts.NewRandomWallet(chainID, nil, nil) +if err != nil { + log.Panic(err) +} + +// create new wallet with connection to L2 +wallet, err = wallet.Connect(&client) +if err != nil { + log.Panic(err) +} +``` + +### `ConnectL1` + +Returns a new instance of `Wallet` with the provided client for the L1 network. + +#### Inputs + +| Parameter | Type | Description | +| --------- | -------------------------------------------------------------------------------------------------- | ----------- | +| `client` | [`*ethclient.Client`](https://pkg.go.dev/github.com/ethereum/go-ethereum@v1.12.0/ethclient#Client) | L1 client. | + +```go +ConnectL1(client *ethclient.Client) (*Wallet, error) +``` + +#### Example + +```go +chainID, err := client.ChainID(context.Background()) +if err != nil { + log.Panic(err) +} + +wallet, err = accounts.NewRandomWallet(chainID, nil, nil) +if err != nil { + log.Panic(err) +} + +// create new wallet with connection to L1 +wallet, err = wallet.Connect(ðClient) +if err != nil { + log.Panic(err) +} +``` + +### `Nonce` + +Returns the account nonce of the associated account. The block number can be `nil`, in which case the nonce is taken +from the latest known block. + +#### Inputs + +| Parameter | Type | Description | +| ------------- | --------------------- | ------------- | +| `ctx` | `context.Context` | Context. | +| `blockNumber` | `*big.Int` (optional) | Block number. | + +```go +Nonce(ctx context.Context, blockNumber *big.Int) (uint64, error) +``` + +#### Example + +```go +nonce, err := wallet.Nonce(context.Background(), big.NewInt(9000)) +if err != nil { + log.Panic(err) +} +fmt.Println("Nonce: ", nonce) +``` + +### `PendingNonce` + +Returns the account nonce of the associated account in the pending state. +This is the nonce that should be used for the next transaction. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +PendingNonce(ctx context.Context) (uint64, error) +``` + +#### Example + +```go +nonce, err := wallet.PendingNonce(context.Background()) +if err != nil { + log.Panic(err) +} +fmt.Println("Nonce: ", nonce) +``` diff --git a/content/sdk/20.go/02.api/01.accounts/04.walletl1.md b/content/sdk/20.go/02.api/01.accounts/04.walletl1.md new file mode 100644 index 00000000..177f3487 --- /dev/null +++ b/content/sdk/20.go/02.api/01.accounts/04.walletl1.md @@ -0,0 +1,1002 @@ +--- +title: WalletL1 +description: Manages and interacts with accounts on L1 +tags: ["zksync", "walletL1", "account management", "go", "sdk"] +--- + +The `WalletL1` class provides functionalities for managing and interacting with accounts on +the Layer 1 (L1) network. It includes methods for creating wallets, querying contracts, checking balances, and +performing transactions on the Ethereum network. + +### `Init` + +Creates an instance of WalletL1 associated with the account provided by the raw private key. + +```go +func NewWalletL1(rawPrivateKey []byte, clientL1 *ethclient.Client, clientL2 *clients.Client) (*WalletL1, error +``` + +Creates an instance of WalletL1 associated with the account provided by the signer. + +```go +NewWalletL1FromSigner(signer *Signer, clientL1 *ethclient.Client, clientL2 *clients.Client) (*WalletL1, error) +``` + +#### Example + +```go +PrivateKey := os.Getenv("PRIVATE_KEY") +ZkSyncEraProvider := "https://sepolia.era.zksync.dev" +EthereumProvider := "https://rpc.ankr.com/eth_sepolia" + +client, err := clients.Dial(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +ethClient, err := ethclient.Dial(EthereumProvider) +if err != nil { + log.Panic(err) +} +defer ethClient.Close() + +wallet, err := accounts.NewWalletL1(common.Hex2Bytes(PrivateKey), &client, ethClient) +if err != nil { + log.Panic(err) +} +``` + +### `MainContract` + +Returns the ZKsync L1 smart contract. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +MainContract(ctx context.Context) (*zksync.IZkSync, error) +``` + +#### Example + +```go +mainContract, err := wallet.MainContract(context.Background()) +if err != nil { + log.Panic(err) +} +``` + +### `BridgehubContract` + +Returns the Bridgehub L1 smart contract. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +BridgehubContract(_ context.Context) (*bridgehub.IBridgehub, error) +``` + +#### Example + +```go +bridgehub, err := wallet.BridgehubContract(context.Background()) +if err != nil { + log.Panic(err) +} +``` + +### `L1BridgeContracts` + +Returns L1 bridge contracts. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +L1BridgeContracts(ctx context.Context) (*zkTypes.L1BridgeContracts, error) +``` + +#### Example + +```go +contracts, err := wallet.L1BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +``` + +### `BaseToken` + +Returns the address of the base token on L1. + +#### Inputs + +| Parameter | Type | Description | +|-----------|----------------------------------------------------------| ----------- | +| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | + +```go +BaseToken(opts *CallOpts) (common.Address, error) +``` + +#### Example + +```go +baseToken, err := wallet.BaseToken(nil) +if err != nil { + log.Panic(err) +} +fmt.Println("Base token: ", baseToken) +``` + +### `IsEthBasedChain` + +Returns whether the chain is ETH-based. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +IsEthBasedChain(ctx context.Context) (bool, error) +``` + +#### Example + +```go +isEthBased, err := wallet.IsEthBasedChain(context.Background()) +if err != nil { + log.Panic(err) +} +fmt.Println("Is ETH-based chain: ", isEthBased) +``` + +### `BalanceL1` + +Returns the balance of the specified token on L1 that can be either ETH or any ERC20 token. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------------ | -------------- | +| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `token` | `common.Address` | Token address. | + +```go +BalanceL1(opts *CallOpts, token common.Address) (*big.Int, error) +``` + +#### Example + +```go +balance, err := wallet.BalanceL1(nil, utils.EthAddress) +if err != nil { + log.Panic(err) +} +fmt.Println("Balance: ", balance) +``` + +### `AllowanceL1` + +Returns the amount of approved tokens for a specific L1 bridge. + +#### Inputs + +| Parameter | Type | Description | +| --------------- | ------------------------------------------------ | --------------- | +| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `token` | `common.Address` | Token address. | +| `bridgeAddress` | `common.Address` | Bridge address. | + +```go +AllowanceL1(opts *CallOpts, token common.Address, bridgeAddress common.Address) (*big.Int, error) +``` + +#### Example + +```go +// The Crown token on testnet +TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") + +contracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +bridgeAllowance, err := wallet.AllowanceL1(nil, TokenAddress, contracts.L1Erc20DefaultBridge) +if err != nil { + log.Panic(err) +} +fmt.Println("Bridge allowance: ", bridgeAllowance) +``` + +### `L2TokenAddress` + +Returns the corresponding address on the L2 network for the token on the L1 network. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------------- | +| `ctx` | `context.Context` | Context. | +| `token` | `common.Address` | L1 token address. | + +```go +L2TokenAddress(ctx context.Context, token common.Address) (common.Address, error) +``` + +#### Example + +```go +l1DAI := common.HexToAddress("0x5C221E77624690fff6dd741493D735a17716c26B") +l2DAI, err := wallet.L2TokenAddress(context.Background(), l1DAI) +if err != nil { + log.Panic(err) +} +fmt.Println("L2 DAI address: ", l2DAI) +``` + +### `ApproveERC20` + +Approves the specified amount of tokens for the specified L1 bridge. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------------- | +| `ctx` | `context.Context` | Context. | +| `token` | `common.Address` | L1 token address. | +| `amount` | `*big.Int` | Approval amount. | + +```go +ApproveERC20(auth *TransactOpts, token common.Address, amount *big.Int, bridgeAddress common.Address) (*types.Transaction, error) +``` + +#### Example + +```go +// The Crown token on testnet +TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") + +contracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +tx, err := wallet.ApproveERC20(nil, TokenAddress, contracts.L1Erc20DefaultBridge) +if err != nil { + log.Panic(err) +} +fmt.Println("Tx: ", tx.Hash()) +``` + +### `BaseCost` + +Returns base cost for L2 transaction. + +#### Inputs + +| Parameter | Type | Description | +| ------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------- | +| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `gasLimit` | `*big.Int` | The gasLimit for the the L2 contract call. | +| `gasPerPubdataByte` | `*big.Int` | The L2 gas price for each published L1 calldata byte. | +| `gasPrice` | `*big.Int` (optional) | The L1 gas price of the L1 transaction that will send the request for an execute call. | + +```go +BaseCost(opts *CallOpts, gasLimit, gasPerPubdataByte, gasPrice *big.Int) (*big.Int, error) +``` + +#### Example + +```go +gasPrice, err := client.SuggestGasPrice(context.Background()) +if err != nil { + log.Panic(err) +} + +baseCost, err := wallet.BaseCost(nil, big.NewInt(9000), utils.RequiredL1ToL2GasPerPubdataLimit, gasPrice) +if err != nil { + log.Panic(err) +} +fmt.Println("Base cost: ", baseCost) +``` + +### `DepositAllowanceParams` + +Returns the parameters for the approval token transaction based on the deposit token and amount. +Some deposit transactions require multiple approvals. Existing allowance for the bridge is not checked; +allowance is calculated solely based on the specified amount. + +#### Inputs + +| Parameter | Type | Description | +|---------------------| ---------------------------------------- | -------------------------------------------------------------------------------------- | +| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `msg` | [`DepositCallMsg`](/sdk/go/types/accounts#depositcallmsg) | Deposit call parameters. | + +```go +DepositAllowanceParams(opts *CallOpts, msg DepositCallMsg) ([]struct { + Token common.Address + Allowance *big.Int +}, error) +``` + +#### Example + +Get allowance parameters for depositing token on ETH-based chain. + +```go +msg := accounts.DepositCallMsg{ + Token: common.HexToAddress(""), + To: Receiver, + Amount: big.NewInt(5), +} + +allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + +Get allowance parameters for depositing ETH on non-ETH-based chain. + +```go +msg := accounts.DepositCallMsg{ + Token: utils.LegacyEthAddress, + To: Receiver, + Amount: big.NewInt(7_000_000_000), +} + +allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + +Get allowance parameters for depositing base token on non-ETH-based chain. + +```go +token, err := wallet.BaseToken(nil) +if err != nil { + log.Panic(err) +} + +msg := accounts.DepositCallMsg{ + Token: token, + To: Receiver, + Amount: big.NewInt(7_000_000_000), +} + +allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + +Get allowance parameters for depositing non-base token on non-ETH-based chain. + +```go +msg := accounts.DepositCallMsg{ + Token: common.HexToAddress(""), + To: Receiver, + Amount: big.NewInt(5), +} + +allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +approveTx, err = wallet.ApproveERC20(nil, allowanceParams[1].Token, allowanceParams[1].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + +```go +ZkSyncEraProvider := "https://testnet.era.zksync.dev" + +client, err := clients.Dial(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +gasPrice, err := client.SuggestGasPrice(context.Background()) +if err != nil { + log.Panic(err) +} + +baseCost, err := wallet.BaseCost(nil, big.NewInt(9000), utils.RequiredL1ToL2GasPerPubdataLimit, gasPrice) +if err != nil { + log.Panic(err) +} +fmt.Println("Base cost: ", baseCost) +``` + +### `Deposit` + +Transfers the specified token from the associated account on the L1 network to the target account on the L2 network. +The token can be either ETH or any ERC20 token. For ERC20 tokens, enough approved tokens must be associated with the +specified L1 bridge (default one or the one defined in `BridgeAddress`). In this case, depending on is the chain +ETH-based or not `ApproveERC20` or `ApproveBaseERC20` can be enabled to perform token approval. +to perform token approval. If there are already enough approved tokens for the L1 bridge, token approval will be +skipped. To check the amount of approved tokens for a specific bridge, use the [`AllowanceL1`](#allowancel1) method. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------- |--------------------------------| +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`DepositTransaction`](/sdk/go/types/accounts#deposittransaction) | Deposit transaction parameters.| + +```go +Deposit(auth *TransactOpts, tx DepositTransaction) (*types.Transaction, error) +``` + +#### Example + +Deposit ETH on ETH-based chain. + +```go +tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ + To: wallet.Address(), + Token: utils.LegacyEthAddress, + Amount: amount, + RefundRecipient: wallet.Address(), +}) +if err != nil { + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) +} +``` + +Deposit token on ETH-based chain. + +```go +tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ + To: wallet.Address(), + Token: L1Dai, + Amount: amount, + ApproveERC20: true, + RefundRecipient: wallet.Address(), +}) +if err != nil { + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) +} +``` + +Deposit ETH on non-ETH-based chain. + +```go +tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ + To: wallet.Address(), + Token: utils.LegacyEthAddress, + Amount: amount, + ApproveBaseERC20: true, + RefundRecipient: wallet.Address(), +}) +if err != nil { + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) +} +``` + +Deposit base token on non-ETH-based chain. + +```go +baseToken, err := wallet.BaseToken(nil) +if err != nil { + log.Panic(err) +} + +tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ + To: wallet.Address(), + Token: baseToken, + Amount: amount, + ApproveBaseERC20: true, + RefundRecipient: wallet.Address(), +}) +if err != nil { + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) +} +``` + +Deposit non-base token on non-ETH-based chain. + +```go +tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ + To: wallet.Address(), + Token: L1Dai, + Amount: amount, + ApproveERC20: true, + ApproveBaseERC20: true, + RefundRecipient: wallet.Address(), +}) +if err != nil { + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) +} +``` + +### `EstimateGasDeposit` + +Estimates the amount of gas required for a deposit transaction on L1 network. Gas of approving ERC20 token is not +included in the estimation. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------------- | ------------------------ | +| `ctx` | `context.Context` | Context. | +| `msg` | [`DepositCallMsg`](/sdk/go/types/accounts#depositcallmsg) | Deposit call parameters. | + +```go +EstimateGasDeposit(ctx context.Context, msg DepositCallMsg) (uint64, error) +``` + +#### Example + +```go +depositGas, err := wallet.EstimateGasDeposit(context.Background(), accounts.DepositCallMsg{ + To: wallet.Address(), + Token: utils.EthAddress, + Amount: big.NewInt(7_000_000_000), +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Deposit gas: ", depositGas) +``` + +### `FullRequiredDepositFee` + +Retrieves the full needed ETH fee for the deposit on both L1 and L2 networks. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------------- | ------------------------ | +| `ctx` | `context.Context` | Context. | +| `msg` | [`DepositCallMsg`](/sdk/go/types/accounts#depositcallmsg) | Deposit call parameters. | + +```go +FullRequiredDepositFee(ctx context.Context, msg DepositCallMsg) (*FullDepositFee, error) +``` + +#### Example + +```go +fee, err := wallet.FullRequiredDepositFee(context.Background(), accounts.DepositCallMsg{ + To: wallet.Address(), + Token: utils.EthAddress, + Amount: big.NewInt(7_000_000_000), +}) +if err != nil { + log.Panic(err) +} +fmt.Printf("Fee: %+v\n", fee) +``` + +### `FinalizeWithdraw` + +Proves the inclusion of the L2 -> L1 withdrawal message. + +#### Inputs + +| Parameter | Type | Description | +| ---------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `withdrawalHash` | `common.Hash` | Hash of the L2 transaction where the withdrawal was initiated. | +| `index` | `int` | In case there were multiple withdrawals in one transaction, you may pass an index of the withdrawal you want to finalize. | + +```go +FinalizeWithdraw(auth *TransactOpts, withdrawalHash common.Hash, index int) (*types.Transaction, error) +``` + +#### Example + +```go +withdrawalHash := common.HexToHash("") +finalizeWithdrawTx, err := wallet.FinalizeWithdraw(nil, withdrawalHash, 0) +if err != nil { + log.Panic(err) +} +fmt.Println("Finalize withdraw transaction: ", finalizeWithdrawTx.Hash()) +``` + +### `IsWithdrawFinalized` + +Checks if the withdrawal finalized on L1 network. + +#### Inputs + +| Parameter | Type | Description | +| ---------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- | +| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `withdrawalHash` | `common.Hash` | Hash of the L2 transaction where the withdrawal was initiated. | +| `index` | `int` | In case there where multiple withdrawals in one transaction, you may pass an index of the withdrawal you want to finalize. | + +```go +IsWithdrawFinalized(opts *CallOpts, withdrawalHash common.Hash, index int) (bool, error) +``` + +#### Example + +```go +withdrawalHash := common.HexToHash("") +isFinalized, err := wallet.IsWithdrawFinalized(nil, withdrawalHash, 0) +if err != nil { + log.Panic(err) +} +fmt.Println("Is withdrawal finalized: ", isFinalized) +``` + +### `ClaimFailedDeposit` + +Withdraws funds from the initiated deposit, which failed when finalizing on L2. If the deposit L2 transaction has +failed, it sends an L1 transaction calling ClaimFailedDeposit method of the L1 bridge, which results in returning +L1 tokens back to the depositor, otherwise throws the error. + +#### Inputs + +| Parameter | Type | Description | +| ------------- | --------------------------------------------------------- | ---------------------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `depositHash` | `common.Hash` | The L2 transaction hash of the failed deposit. | + +```go +ClaimFailedDeposit(auth *TransactOpts, depositHash common.Hash) (*types.Transaction, error) +``` + +#### Example + +```go +failedDepositL2Hash := common.HexToHash("") +cfdTx, err := wallet.ClaimFailedDeposit(nil, failedDepositL2Hash) +if err != nil { + log.Panic(err) +} +fmt.Println("ClaimFailedDeposit hash: ", cfdTx.Hash) +``` + +### `RequestExecute` + +Request execution of L2 transaction from L1. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------------------------------------------------------------- | --------------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`RequestExecuteTransaction`](/sdk/go/types/accounts#requestexecutetransaction) | Request execute transaction parameters. | + +```go +RequestExecute(auth *TransactOpts, tx RequestExecuteTransaction) (*types.Transaction, error) +``` + +#### Example + +```go +contractAddress := common.HexToAddress("") +requestExecuteTx, err := wallet.RequestExecute(nil, accounts.RequestExecuteTransaction{ + ContractAddress: contractAddress, + L2Value: big.NewInt(7_000_000_000), + L2GasLimit: big.NewInt(90_000), + GasPerPubdataByte: utils.RequiredL1ToL2GasPerPubdataLimit, + RefundRecipient: to, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Request execute tx: ", requestExecuteTx.Hash()) +``` + +### `EstimateGasRequestExecute` + +Estimates the amount of gas required for a request execute transaction. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------------- | -------------------------------- | +| `ctx` | `context.Context` | Context. | +| `msg` | [`RequestExecuteCallMsg`](/sdk/go/types/accounts#requestexecutecallmsg) | Request execute call parameters. | + +```go +EstimateGasRequestExecute(ctx context.Context, msg RequestExecuteCallMsg) (uint64, error) +``` + +#### Example + +```go +contractAddress := common.HexToAddress("") +gas, err := wallet.EstimateGasRequestExecute(context.Background(), accounts.RequestExecuteCallMsg{ + ContractAddress: contractAddress, + L2Value: big.NewInt(7_000_000_000), + L2GasLimit: big.NewInt(90_000), + GasPerPubdataByte: utils.RequiredL1ToL2GasPerPubdataLimit, + RefundRecipient: to, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Gas: ", gas) +``` + +### `RequestExecuteAllowanceParams` + +Returns the parameters for the approval token transaction based on the request execute transaction. +Existing allowance for the bridge is not checked; allowance is calculated solely based on the specified transaction. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------------- | -------------------------------- | +| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `msg` | [`RequestExecuteCallMsg`](/sdk/go/types/accounts#requestexecutecallmsg) | Request execute call parameters. | + +```go +RequestExecuteAllowanceParams(opts *CallOpts, msg RequestExecuteCallMsg) (AllowanceParams, error) +``` + +#### Example + +```go +msg := accounts.RequestExecuteCallMsg{ + ContractAddress: wallet.Address(), + L2Value: big.NewInt(7_000_000_000), + Value: big.NewInt(0), +} +allowanceParams, err := wallet.RequestExecuteAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} + +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} + +approveTx, err := wallet.ApproveERC20(nil, allowanceParams.Token, allowanceParams.Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} + +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + +### `EstimateCustomBridgeDepositL2Gas` + +Used by [`EstimateDefaultBridgeDepositL2Gas`](#estimatedefaultbridgedepositl2gas) to estimate L2 gas +required for token bridging via a custom ERC20 bridge. + +::callout{icon="i-heroicons-information-circle" color="blue"} +See the [default bridges documentation](https://docs.zksync.io/build/developer-reference/bridging-assets#default-bridges) +:: + +#### Inputs + +| Parameter | Type | Description | +| ------------------- | --------------------------- | -------------------------------- | +| `ctx` | `context.Context` | Context. | +| `l1BridgeAddress` | `common.Address` | L1 bridge address. | +| `l2BridgeAddress` | `common.Address` | L2 bridge address. | +| `token` | `common.Address` | Token address. | +| `amount` | `*big.Int` | Deposit amount. | +| `to` | `common.Address` | Recipient address. | +| `bridgeData` | `[]byte` | Bridge data. | +| `from` | `common.Address` (optional) | Sender address. | +| `gasPerPubdataByte` | `*big.Int` (optional) | Current gas per byte of pubdata. | + +```go +EstimateCustomBridgeDepositL2Gas(ctx context.Context, l1BridgeAddress, l2BridgeAddress, token common.Address, + amount *big.Int, to common.Address, bridgeData []byte, from common.Address, gasPerPubdataByte *big.Int) (uint64, error) +``` + +#### Example + +```go +L1BridgeAddress := common.HexToAddress("") +Token := common.HexToAddress("") +From := common.HexToAddress("") +To := common.HexToAddress("") + + +bridge, err := l1bridge.NewIL1Bridge(L1BridgeAddress, ethClient) +if err != nil { + log.Panic(err) +} +l2BridgeAddress, err := bridge.L2Bridge(nil) +if err != nil { + log.Panic(err) +} +customBridgeData, err := utils.Erc20DefaultBridgeData(Token, ethClient) +if err != nil { + log.Panic(err) +} + +gas, err := wallet1.EstimateCustomBridgeDepositL2Gas(context.Background(), L1BridgeAddress, l2BridgeAddress, Token, + big.NewInt(7), To, customBridgeData, From, utils.RequiredL1ToL2GasPerPubdataLimit) +if err != nil { + log.Panic(err) +} +fmt.Println("L2 gas: ", gas) +``` + +### `EstimateDefaultBridgeDepositL2Gas` + +Returns an estimation of L2 gas required for token bridging via the default ERC20 bridge. + +::callout{icon="i-heroicons-information-circle" color="blue"} +See the [default bridges documentation](https://docs.zksync.io/build/developer-reference/bridging-assets#default-bridges) +:: + +#### Inputs + +| Parameter | Type | Description | +| ------------------- | --------------------------- | -------------------------------- | +| `ctx` | `context.Context` | Context. | +| `token` | `common.Address` | Token address. | +| `amount` | `*big.Int` | Deposit amount. | +| `to` | `common.Address` | Recipient address. | +| `from` | `common.Address` (optional) | Sender address. | +| `gasPerPubdataByte` | `*big.Int` (optional) | Current gas per byte of pubdata. | + +```go +EstimateDefaultBridgeDepositL2Gas(ctx context.Context, token common.Address, amount *big.Int, + to, from common.Address, gasPerPubdataByte *big.Int) (uint64, error) +``` + +#### Example + +```go +Token := common.HexToAddress("") +From := common.HexToAddress("") +To := common.HexToAddress("") +gas, err := wallet1.EstimateDefaultBridgeDepositL2Gas( + context.Background(), Token, big.NewInt(7), To, From, utils.RequiredL1ToL2GasPerPubdataLimit, +) +if err != nil { + log.Panic(err) +} +fmt.Println("L2 gas: ", gas) +``` diff --git a/content/sdk/20.go/02.api/01.accounts/05.walletl2.md b/content/sdk/20.go/02.api/01.accounts/05.walletl2.md new file mode 100644 index 00000000..2c721bef --- /dev/null +++ b/content/sdk/20.go/02.api/01.accounts/05.walletl2.md @@ -0,0 +1,523 @@ +--- +title: WalletL2 +description: Manages and interacts with accounts on L2 +tags: ["zksync", "walletL2", "account management", "go", "sdk"] +--- + +The `WalletL2` class provides functionalities for managing and interacting with accounts on +the Layer 2 (L2) network. It includes methods for creating wallets, querying balances, transferring tokens, and +interacting with smart contracts on the ZKsync network. + +### `Init` + +Creates an instance of `WalletL2` associated with the account provided by the raw private key. + +```go +func NewWalletL2(rawPrivateKey []byte, client *clients.Client) (*WalletL2, error) +``` + +Creates an instance of `WalletL2`. The `client` can be optional; if it is not provided, only +`SignTransaction`, `Address`, `Signer` can be performed, as the rest of the functionalities +require communication to the network. + +```go +func NewWalletL2FromSigner(signer *Signer, client *clients.Client) (*WalletL2, error) +``` + +#### Example + +```go +PrivateKey := os.Getenv("PRIVATE_KEY") +ZkSyncEraProvider := "https://testnet.era.zksync.dev" + +client, err := clients.Dial(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client) +if err != nil { + log.Panic(err) +} + +``` + +### `Address` + +Returns the address of the associated account. + +```go +Address() common.Address +``` + +#### Example + +```go +fmt.Println("Address: ", wallet.Address()) +``` + +### `Signer` + +Returns the signer of the associated account. + +```go +Signer() Signer +``` + +#### Example + +```go +fmt.Printf("Signer %+v\n", wallet.Signer()) +``` + +### `Balance` + +Returns the balance of the specified token that can be either ETH or any ERC20 token. The block number can be `nil`, +in which case the balance is taken from the latest known block. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------------- | +| `ctx` | `context.Context` | Context. | +| `token` | `common.Address` | L2 token address. | +| `at` | `*big.Int` | Block number. | + +```go +Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error) +``` + +#### Example + +```go +balance, err := wallet.Balance(context.Background(), utils.EthAddress, nil) +if err != nil { + log.Panic(err) +} +fmt.Println("Balance: ", balance) +``` + +### `AllBalances` + +Returns all balances for confirmed tokens given by an associated account. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +AllBalances(ctx context.Context) (map[common.Address]*big.Int, error) +``` + +#### Example + +```go +balances, err := wallet.AllBalances(context.Background()) +if err != nil { + log.Panic(err) +} +fmt.Printf("Balances: %+v\n", balances) +``` + +### `L2BridgeContracts` + +Returns L2 bridge contracts. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +L2BridgeContracts(ctx context.Context) (*zkTypes.L2BridgeContracts, error) +``` + +#### Example + +```go +contracts, err := wallet.L2BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +``` + +### `DeploymentNonce` + +Returns the deployment nonce of the account. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------------ | ------------- | +| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | + +```go +func (a *WalletL2) DeploymentNonce(opts *CallOpts) (*big.Int, error) +``` + +#### Example + +```go +deploymentNonce, err := wallet.DeploymentNonce(nil) +if err != nil { + log.Panic(err) +} +``` + +### `IsBaseToken` + +Returns whether the token is the base token. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- |----------------| +| `ctx` | `context.Context` | Context. | +| `token` | `common.Address` | Token address. | + +```go +IsBaseToken(ctx context.Context, token common.Address) (bool, error) +``` + +#### Example + +```go +isBaseToken, err := wallet.IsBaseToken( + context.Background(), + common.HexToAddress("0x5C221E77624690fff6dd741493D735a17716c26B") +) +if err != nil { + log.Panic(err) +} +fmt.Println("Is base token: ", isBaseToken) +``` + +### `Withdraw` + +Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network +to the target account on L1 network. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------------- | ---------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`WithdrawalTransaction`](/sdk/go/types/accounts#withdrawaltransaction) | Withdrawal transaction parameters. | + +```go +Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (*types.Transaction, error) +``` + +#### Example + +```go +tx, err := wallet.Withdraw(nil, accounts.WithdrawalTransaction{ + To: wallet.Address(), + Amount: big.NewInt(1_000_000_000_000_000_000), + Token: utils.EthAddress, +}) +if err != nil { + panic(err) +} +fmt.Println("Withdraw transaction: ", tx.Hash()) +``` + +### `EstimateGasWithdraw` + +Estimates the amount of gas required for a withdrawal transaction. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------------------- | --------------------------- | +| `ctx` | `context.Context` | Context. | +| `msg` | [`WithdrawalCallMsg`](/sdk/go/types/accounts#withdrawalcallmsg) | Withdrawal call parameters. | + +```go +EstimateGasWithdraw(ctx context.Context, msg WithdrawalCallMsg) (uint64, error) +``` + +#### Example + +```go +gas, err := wallet.EstimateGasWithdraw(context.Background(), accounts.WithdrawalCallMsg{ + To: wallet.Address(), + Amount: big.NewInt(7_000_000), + Token: utils.EthAddress, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Gas: ", gas) +``` + +### `Transfer` + +Moves the ETH or any ERC20 token from the associated account to the target account. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------------------------------------------------- | -------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`TransferTransaction`](/sdk/go/types/accounts#transfertransaction) | Transfer transaction parameters. | + +```go +Transfer(auth *TransactOpts, tx TransferTransaction) (*types.Transaction, error) +``` + +#### Example + +```go +tx, err := wallet.Transfer(nil, accounts.TransferTransaction{ + To: common.HexToAddress(""), + Amount: big.NewInt(7_000_000_000), + Token: utils.EthAddress, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Transaction: ", tx.Hash()) +``` + +### `EstimateGasTransfer` + +Estimates the amount of gas required for a transfer transaction. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------- | ------------------------- | +| `ctx` | `context.Context` | Context. | +| `msg` | [`TransferCallMsg`](/sdk/go/types/accounts#transfercallmsg) | Transfer call parameters. | + +```go +EstimateGasTransfer(ctx context.Context, msg TransferCallMsg) (uint64, error) +``` + +#### Example + +```go +gas, err := wallet.EstimateGasTransfer(context.Background(), accounts.TransferCallMsg{ + To: common.HexToAddress(""), + Amount: big.NewInt(7_000_000_000), + Token: utils.EthAddress, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Gas: ", gas) +``` + +### `CallContract` + +Executes a message call for EIP-712 transaction, which is directly executed in the VM of the node, but never mined +into the blockchain. + +#### Inputs + +| Parameter | Type | Description | +| ------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `ctx` | `context.Context` | Context. | +| `msg` | [`CallMsg`](/sdk/go/types/accounts#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `blockNumber` | `*big.Int` (optional) | Selects the block height at which the call runs. It can be `nil`, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available. | + +```go +CallContract(ctx context.Context, msg CallMsg, blockNumber *big.Int) ([]byte, error) +``` + +#### Example + +```go +// The Crown token on testnet +TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") + +tokenAbi, err := erc20.IERC20MetaData.GetAbi() +if err != nil { + log.Panic(err) +} +symbolCalldata, err := tokenAbi.Pack("symbol") +if err != nil { + log.Panic(err) +} + +result, err := wallet.CallContract(context.Background(), types.CallMsg{ + CallMsg: ethereum.CallMsg{ + To: &TokenAddress, + Data: symbolCalldata, + }, +}, nil) +if err != nil { + log.Panic(err) +} +unpack, err := tokenAbi.Unpack("symbol", result) +if err != nil { + log.Panic(err) +} +symbol := *abi.ConvertType(unpack[0], new(string)).(*string) +fmt.Println("Symbol: ", symbol) +``` + +### PopulateTransaction + +Designed for users who prefer a simplified approach by providing only the necessary data to create a valid +[EIP-712 transaction](/sdk/go/types/types#transaction712). The only required fields are `Transaction.To` and either +`Transaction.Data` or `Transaction.Value` (or both, if the method is payable). +Any other fields that are not set will be prepared by this method. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------- | ----------------------- | +| `ctx` | `context.Context` | Context. | +| `tx` | [`Transaction`](/sdk/go/types/accounts#transaction) | Transaction parameters. | + +```go +PopulateTransaction(ctx context.Context, tx Transaction) (*zkTypes.Transaction712, error) +``` + +#### Example + +```go +// The Crown token on testnet +TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") +// Paymaster for Crown token on testnet +PaymasterAddress := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46") +ReceiptAddress := common.HexToAddress("0xa61464658AfeAf65CccaaFD3a512b69A83B77618") + +abi, err := erc20.IERC20MetaData.GetAbi() +if err != nil { + log.Panic(err) +} + +// Encode transfer function from token contract +calldata, err := abi.Pack("transfer", ReceiptAddress, big.NewInt(7)) +if err != nil { + log.Panic(err) +} + +preparedTx, err := wallet.PopulateTransaction(context.Background(), &accounts.Transaction{ + To: &TokenAddress, + Data: calldata, +}) +fmt.Printf("Prepared tx: %+v\n", preparedTx) +``` + +### `SignTransaction` + +Returns a signed transaction that is ready to be broadcast to the network. The input transaction must be a valid +transaction with all fields having appropriate values. To obtain a valid transaction, you can use the +[`PopulateTransaction`](#populatetransaction) method. + +#### Inputs + +| Parameter | Type | Description | +| --------- |----------------------------------------------------------------| ------------------------------- | +| `tx` | [`zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | EIP-712 transaction parameters. | + +```go +SignTransaction(tx *zkTypes.Transaction712) ([]byte, error) +``` + +#### Example + +```go +// The Crown token on testnet +TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") +// Paymaster for Crown token on testnet +PaymasterAddress := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46") +ReceiptAddress := common.HexToAddress("0xa61464658AfeAf65CccaaFD3a512b69A83B77618") + +abi, err := erc20.IERC20MetaData.GetAbi() +if err != nil { + log.Panic(err) +} + +// Encode transfer function from token contract +calldata, err := abi.Pack("transfer", ReceiptAddress, big.NewInt(7)) +if err != nil { + log.Panic(err) +} + +preparedTx, err := wallet.PopulateTransaction(context.Background(), &accounts.Transaction{ + To: &TokenAddress, + Data: calldata, +}) + +signedTx, err := wallet.SignTransaction(preparedTx) +if err != nil { + log.Panic(err) +} +fmt.Printf("Signed tx: %+v\n", signedTx) +``` + +### `SendTransaction` + +Injects a transaction into the pending pool for execution. Any unset transaction fields are prepared using the +`PopulateTransaction` method. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------- | ----------------------- | +| `ctx` | `context.Context` | Context. | +| `tx` | [`Transaction`](/sdk/go/types/accounts#transaction) | Transaction parameters. | + +```go +SendTransaction(ctx context.Context, tx *Transaction) (common.Hash, error) +``` + +#### Example + +```go +// The Crown token on testnet +TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") +// Paymaster for Crown token on testnet +PaymasterAddress := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46") +ReceiptAddress := common.HexToAddress("0xa61464658AfeAf65CccaaFD3a512b69A83B77618") + +abi, err := erc20.IERC20MetaData.GetAbi() +if err != nil { + log.Panic(err) +} + +// Encode transfer function from token contract +calldata, err := abi.Pack("transfer", ReceiptAddress, big.NewInt(7)) +if err != nil { + log.Panic(err) +} + +// Create paymaster parameters with encoded paymaster input +paymasterParams, err := utils.GetPaymasterParams( + PaymasterAddress, + &zkTypes.ApprovalBasedPaymasterInput{ + Token: TokenAddress, + MinimalAllowance: big.NewInt(1), + InnerInput: []byte{}, + }) +if err != nil { + log.Panic(err) +} + +hash, err := wallet.SendTransaction(context.Background(), &accounts.Transaction{ + To: &TokenAddress, + Data: calldata, + Meta: &types.Eip712Meta{ + PaymasterParams: paymasterParams, + }, +}) +if err != nil { + log.Panic(err) +} + +_, err = client.WaitMined(context.Background(), hash) +if err != nil { + log.Panic(err) +} + +fmt.Println("Tx: ", hash) +``` diff --git a/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md b/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md new file mode 100644 index 00000000..a417c0ca --- /dev/null +++ b/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md @@ -0,0 +1,57 @@ +--- +title: SmartAccount +description: Flexible signer for various payloads +tags: ["zksync", "smart account", "signer", "go", "sdk"] +--- + +A `SmartAccount` is a signer which can be configured to sign various payloads using a provided secret. +The secret can be in any form, allowing for flexibility when working with different account implementations. +The `SmartAccount` is bound to a specific address and provides the ability to define custom method for populating transactions +and custom signing method used for signing messages, typed data, and transactions. + +### `Init` + +Creates a new `SmartAccount` instance. By default, it uses [`SignPayloadWithECDSA`](/sdk/go/smart-account-utils#signpayloadwithecdsa) +as a signer and [`PopulateTransactionECDSA`](/sdk/go/smart-account-utils#populatetransactionecdsa) as a builder and +requires private key in hex format to be provided. + +#### Inputs + +| Parameter | Type | Description | +|-----------|--------------------------------------------------------------------|---------------------------------------------------------| +| `address` | `common.Address` | Account address. | +| `secret` | `interface{}` | Secret used for signing. | +| `signer` | [`*PayloadSigner`](/sdk/go/types/accounts#payloadsigner) | Function used for signing payload. | +| `builder` | [`*TransactionBuilder`](/sdk/go/types/accounts#transactionbuilder) | Function used for populating transaction. | +| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client to connect to. Can be `nil` for offline usage. | + +```go + +func NewSmartAccount( + address common.Address, + secret interface{}, + signer *PayloadSigner, + builder *TransactionBuilder, + client *clients.BaseClient) *SmartAccount +``` + +#### Examples + +```go +privateKey := os.Getenv("PRIVATE_KEY") +address := common.HexToAddress("") +ZkSyncEraProvider := "https://sepolia.era.zksync.dev" + +client, err := clients.DialBase(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +account := accounts.NewSmartAccount( + address, + privateKey, + &accounts.SignPayloadWithECDSA, + &accounts.PopulateTransactionECDSA, +nil) +``` diff --git a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md new file mode 100644 index 00000000..462f6404 --- /dev/null +++ b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md @@ -0,0 +1,34 @@ +--- +title: NewECDSASmartAccount +description: +tags: +--- + +Creates a `SmartAccount` instance that uses single ECDSA key for signing payload. + +| Parameter | Type | Description | +|--------------|-----------------------------------------------------|----------------------------------------------------------| +| `address` | `common.Address` | Account address. | +| `privateKey` | `string` | The ECDSA private key. | +| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client to connect to. Can be `nil` for offline usage. | + +```go + +func NewECDSASmartAccount(address common.Address, privateKey string, client *clients.BaseClient) *SmartAccount +``` + +#### Example + +```go +privateKey := os.Getenv("PRIVATE_KEY") +address := common.HexToAddress("") +ZkSyncEraProvider := "https://sepolia.era.zksync.dev" + +client, err := clients.DialBase(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +account := accounts.NewECDSASmartAccount(address, privateKey, client) +``` diff --git a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md new file mode 100644 index 00000000..ec5556c6 --- /dev/null +++ b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md @@ -0,0 +1,459 @@ +--- +title: NewMultisigECDSASmartAccount +description: +tags: +--- + +Creates a `SmartAccount` instance that uses multiple ECDSA keys for signing payloads. +The signature is generated by concatenating signatures created by signing with each key individually. + +| Parameter | Type | Description | +|---------------|-----------------------------------------------------|-----------------------------------------------------------| +| `address` | `common.Address` | Account address. | +| `privateKeys` | `[]string` | The list of the ECDSA private keys. | +| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client to connect to. Can be `nil` for offline usage. | + +```go +NewMultisigECDSASmartAccount(address common.Address, privateKeys []string, client *clients.BaseClient) *SmartAccount +``` + +#### Example + +```go +privateKey1 := os.Getenv("PRIVATE_KEY1") +privateKey2 := os.Getenv("PRIVATE_KEY2") +address := common.HexToAddress("") +ZkSyncEraProvider := "https://sepolia.era.zksync.dev" + +client, err := clients.DialBase(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +account := accounts.NewMultisigECDSASmartAccount(address, []string{privateKey1, privateKey2}, client) +``` + +### `Connect` + +Creates a new instance of SmartAccount connected to a client or +detached from any provider if `nil` is provided. + +#### Inputs + +| Parameter | Type | Description | +| --------- |---------------------------------------------------|---------------------------------------------------------------------------------------------------------------| +| `client` | [`*clients.DialBase`](/sdk/go/clients#baseclient) | The client to connect the `SmartAccount` to. If `nil`, the `SmartAccount` will be detached from any provider. | + +```go +Connect(client *clients.BaseClient) *SmartAccount +``` + +#### Example + +```go +privateKey := os.Getenv("PRIVATE_KEY") +ZkSyncEraProvider := "https://testnet.era.zksync.dev" + +client, err := clients.Dial(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +account := accounts.NewECDSASmartAccount(Address1, PrivateKey1, nil) +account = account.Connect(client) +``` + +### `Address` + +Returns the address of the associated account. + +```go +Address() common.Address +``` + +#### Example + +```go +fmt.Println("Address: ", account.Address()) +``` + +### `Balance` + +Returns the balance of the specified token that can be either ETH or any ERC20 token. The block number can be `nil`, +in which case the balance is taken from the latest known block. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------------- | +| `ctx` | `context.Context` | Context. | +| `token` | `common.Address` | L2 token address. | +| `at` | `*big.Int` | Block number. | + +```go +Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error) +``` + +#### Example + +```go +balance, err := account.Balance(context.Background(), utils.EthAddress, nil) +if err != nil { + log.Panic(err) +} +fmt.Println("Balance: ", balance) +``` + +### `AllBalances` + +Returns all balances for confirmed tokens given by an associated account. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +AllBalances(ctx context.Context) (map[common.Address]*big.Int, error) +``` + +#### Example + +```go +balances, err := account.AllBalances(context.Background()) +if err != nil { + log.Panic(err) +} +fmt.Printf("Balances: %+v\n", balances) +``` + +### `Nonce` + +Returns the account nonce of the associated account. The block number can be `nil`, in which case the nonce is taken +from the latest known block. + +#### Inputs + +| Parameter | Type | Description | +| ------------- | --------------------- | ------------- | +| `ctx` | `context.Context` | Context. | +| `blockNumber` | `*big.Int` (optional) | Block number. | + +```go +Nonce(ctx context.Context, blockNumber *big.Int) (uint64, error) +``` + +#### Example + +```go +nonce, err := account.Nonce(context.Background(), big.NewInt(9000)) +if err != nil { + log.Panic(err) +} +fmt.Println("Nonce: ", nonce) +``` + +### `DeploymentNonce` + +Returns the deployment nonce of the account. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------------ | ------------- | +| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | + +```go +DeploymentNonce(opts *CallOpts) (*big.Int, error) +``` + +#### Example + +```go +deploymentNonce, err := account.DeploymentNonce(nil) +if err != nil { + log.Panic(err) +} +``` + +### `PopulateTransaction` + +Populates the transaction `tx` using the provided [`TransactionBuilder`](/sdk/go/types/accounts#transactionbuilder) function. +If `tx.From` is not set, it sets the value from the `Address()` method which can +be utilized in the `TransactionBuilder` function. + +#### Inputs + +| Parameter | Type | Description | +|-----------|----------------------------------------------------------|------------------------------------| +| `ctx` | `context.Context` | Context. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be populated. | + +```go +PopulateTransaction(ctx context.Context, tx *zkTypes.Transaction712) error +``` + +#### Example + +```go +address := common.HexToAddress("") +tx := &zkTypes.Transaction712{ + To: &address, + Value: big.NewInt(7_000_000_000), +} + +err = account.PopulateTransaction(context.Background(), tx) +if err != nil { + log.Panic(err) +} +``` + +### `SignTransaction` + +Returns a signed transaction that is ready to be broadcast to +the network. The `PopulateTransaction` method is called first to ensure that all +necessary properties for the transaction to be valid have been populated. + +#### Inputs + +| Parameter | Type | Description | +|-----------|---------------------------------------------------------|------------------------------------------| +| `ctx` | `context.Context` | Context. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be signed. | + +```go + +SignTransaction(ctx context.Context, tx *zkTypes.Transaction712) ([]byte, error) +``` + +#### Example + +```go +address := common.HexToAddress("") +signedTx, err := account.SignTransaction(context.Background(), &zkTypes.Transaction712{ + To: &address, + Value: big.NewInt(1_000_000_000_000_000_000), // 1ETH +}) +if err != nil { + log.Panic(err) +} +``` + +### `SendTransaction` + +Injects a transaction into the pending pool for execution. +The `SignTransaction` is called first to ensure transaction is properly signed. + +#### Inputs + +| Parameter | Type | Description | +|-----------|---------------------------------------------------------|------------------------------------------| +| `ctx` | `context.Context` | Context. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be signed. | + +```go +SendTransaction(ctx context.Context, tx *zkTypes.Transaction712) (common.Hash, error) +``` + +#### Example + +```go +address := common.HexToAddress("") +txHash, err := account.SendTransaction(context.Background(), &zkTypes.Transaction712{ + To: &address, + Value: big.NewInt(1_000_000_000_000_000_000), // 1ETH +}) +if err != nil { + log.Panic(err) +} +``` + +### `SignMessage` + +Signs a message using the provided [`PayloadSigner`](/sdk/go/types/accounts#payloadsigner) function. + +#### Inputs + +| Parameter | Type | Description | +|-----------|-------------------|--------------------------------------| +| `ctx` | `context.Context` | Context. | +| `message` | `[]byte` | The message that needs to be signed. | + +```go +SignMessage(ctx context.Context, message []byte) ([]byte, error) +``` + +#### Example + +```go +signature, err := account.SignMessage(context.Background(), []byte("Hello World!")) +if err != nil { + log.Panic(err) +} +``` + +### `SignTypedData` + +signs a typed data using the provided [`PayloadSigner`](/sdk/go/types/accounts#payloadsigner) function. + +#### Inputs + +| Parameter | Type | Description | +|-------------|-----------------------|-----------------------------------------| +| `ctx` | `context.Context` | Context. | +| `typedData` | `apitypes.TypedData` | The typed data that needs to be signed. | + +```go +SignTypedData(ctx context.Context, typedData apitypes.TypedData) ([]byte, error) +``` + +#### Example + +```go +signature, err := account.SignTypedData(context.Background(), apitypes.TypedData{ + Domain: apitypes.TypedDataDomain{ + Name: "Example", + Version: "1", + ChainId: math.NewHexOrDecimal256(270), + }, + Types: apitypes.Types{ + "Person": []apitypes.Type{ + {Name: "name", Type: "string"}, + {Name: "age", Type: "uint8"}, + }, + "EIP712Domain": []apitypes.Type{ + {Name: "name", Type: "string"}, + {Name: "version", Type: "string"}, + {Name: "chainId", Type: "uint256"}, + }, + }, + PrimaryType: "Person", + Message: apitypes.TypedDataMessage{ + "name": "John", + "age": hexutil.EncodeUint64(30), + }, +}) +if err != nil { + log.Panic(err) +} +``` + +### `Withdraw` + +Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network +to the target account on L1 network. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------------- | ---------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`WithdrawalTransaction`](/sdk/go/types/accounts#withdrawaltransaction) | Withdrawal transaction parameters. | + +```go +Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (common.Hash, error) +``` + +#### Examples + +Withdraw ETH. + +```go +txHash, err := account.Withdraw(nil, accounts.WithdrawalTransaction{ + To: account.Address(), + Amount: big.NewInt(1_000_000_000_000_000_000), + Token: utils.LegacyEthAddress, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Withdraw transaction: ", txHash) +``` + +Withdraw ETH using paymaster to facilitate fee payment with an ERC20 token. + +```go +token := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F"); // Crown token which can be minted for free +paymaster := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46"); // Paymaster for Crown token + +paymasterParams, err := utils.GetPaymasterParams( + paymaster, + &zkTypes.ApprovalBasedPaymasterInput{ + Token: token, + MinimalAllowance: big.NewInt(1), + InnerInput: []byte{}, +}) +if err != nil { + log.Panic(err) +} + +txHash, err := account.Withdraw(nil, accounts.WithdrawalTransaction{ + To: account.Address(), + Amount: big.NewInt(1_000_000_000_000_000_000), + Token: utils.LegacyEthAddress, + PaymasterParams: paymasterParams, + }) +``` + +### `Transfer` + +Moves the ETH or any ERC20 token from the associated account to the target account. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------------------------------------------------- | -------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `tx` | [`TransferTransaction`](/sdk/go/types/accounts#transfertransaction) | Transfer transaction parameters. | + +```go +Transfer(auth *TransactOpts, tx TransferTransaction) (common.Hash, error) +``` + +#### Examples + +Transfer ETH. + +```go +txHash, err := account.Transfer(nil, accounts.TransferTransaction{ + To: Address2, + Amount: amount, + Token: utils.LegacyEthAddress, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Transaction: ", txHash) +``` + +Transfer ETH using paymaster to facilitate fee payment with an ERC20 token. + +```go +token := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F"); // Crown token which can be minted for free +paymaster := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46"); // Paymaster for Crown token + +paymasterParams, err := utils.GetPaymasterParams( + paymaster, + &zkTypes.ApprovalBasedPaymasterInput{ + Token: token, + MinimalAllowance: big.NewInt(1), + InnerInput: []byte{}, +}) +if err != nil { + log.Panic(err) +} + +txHash, err := account.Transfer(nil, accounts.TransferTransaction{ + To: Address2, + Amount: amount, + Token: utils.LegacyEthAddress, + PaymasterParams: paymasterParams, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Transaction: ", txHash) +``` diff --git a/content/sdk/20.go/08.smart-account-utils.md b/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md similarity index 96% rename from content/sdk/20.go/08.smart-account-utils.md rename to content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md index c5e55935..2b2727da 100644 --- a/content/sdk/20.go/08.smart-account-utils.md +++ b/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md @@ -1,8 +1,13 @@ --- title: SmartAccount Utilities -description: +description: Utilities for signing and populating transactions +tags: ["zksync", "smart account", "utilities", "signing", "go", "sdk"] --- +The `SmartAccount Utilities` provide functions for signing payloads and populating transactions using ECDSA and +multiple ECDSA keys. These utilities offer flexibility and ease of use for developers working with smart accounts in +the ZKsync Era. + ## Functions ### `SignPayloadWithECDSA` diff --git a/content/sdk/20.go/types/01.accounts.md b/content/sdk/20.go/02.api/01.accounts/09.types.md similarity index 98% rename from content/sdk/20.go/types/01.accounts.md rename to content/sdk/20.go/02.api/01.accounts/09.types.md index 75e1a828..df1768b3 100644 --- a/content/sdk/20.go/types/01.accounts.md +++ b/content/sdk/20.go/02.api/01.accounts/09.types.md @@ -1,8 +1,12 @@ --- -title: Accounts Package -description: +title: Types +description: Defines essential types for ZKsync Era +tags: ["zksync", "types", "go", "sdk", "accounts"] --- +This section describes various types used in the ZKsync Era. These types are essential for interacting with the +blockchain, performing transactions, and managing accounts. + ### `AllowanceParams` Contains the parameters required for approval of an ERC20 token. diff --git a/content/sdk/20.go/types/03.eip712.md b/content/sdk/20.go/02.api/02.eip712/00.eip712.md similarity index 58% rename from content/sdk/20.go/types/03.eip712.md rename to content/sdk/20.go/02.api/02.eip712/00.eip712.md index 7046532c..b18e3894 100644 --- a/content/sdk/20.go/types/03.eip712.md +++ b/content/sdk/20.go/02.api/02.eip712/00.eip712.md @@ -1,8 +1,13 @@ --- title: EIP712 Package -description: +description: Provides types and structures for EIP-712 signing +tags: ["eip712", "signing", "ethereum", "go", "sdk"] --- +The `EIP-712` is a standard for typed structured data hashing and signing in Ethereum, which is widely used for +secure and human-readable transaction signing. The package provides the necessary types and structures for EIP-712 +signing. + ### `Domain` Represents the domain parameters used for EIP-712 signing. diff --git a/content/sdk/20.go/06.contracts.md b/content/sdk/20.go/02.api/03.contracts/00.contracts.md similarity index 90% rename from content/sdk/20.go/06.contracts.md rename to content/sdk/20.go/02.api/03.contracts/00.contracts.md index 7aee3741..9a0e8338 100644 --- a/content/sdk/20.go/06.contracts.md +++ b/content/sdk/20.go/02.api/03.contracts/00.contracts.md @@ -1,6 +1,7 @@ --- title: Contracts -description: +description: Provides methods and interfaces for deploying smart contracts and smart accounts on ZKsync Era +tags: ["zksync", "contracts", "deployment", "go", "sdk"] --- The usual way to deploy a contract with the `geth` library is to use `abigen` with the provided `--bin` option, diff --git a/content/sdk/20.go/06.utils.md b/content/sdk/20.go/02.api/04.utilities/00.utils.md similarity index 96% rename from content/sdk/20.go/06.utils.md rename to content/sdk/20.go/02.api/04.utilities/00.utils.md index 8bd55735..b0404c37 100644 --- a/content/sdk/20.go/06.utils.md +++ b/content/sdk/20.go/02.api/04.utilities/00.utils.md @@ -1,9 +1,11 @@ --- -title: Utilities -description: +title: Common Utilities +description: Utilities for building on ZKsync Era +tags: ["zksync", "utilities", "go", "sdk", "blockchain"] --- -Provides essential utilities for building on ZKsync Era. +Provides essential utilities for building on ZKsync Era. These utilities include constants, useful addresses, and +functions that facilitate the development and interaction with the ZKsync blockchain. ## Constants diff --git a/content/sdk/20.go/07.paymaster-utils.md b/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md similarity index 87% rename from content/sdk/20.go/07.paymaster-utils.md rename to content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md index ec3abdbd..b4160172 100644 --- a/content/sdk/20.go/07.paymaster-utils.md +++ b/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md @@ -1,10 +1,12 @@ --- title: Paymaster Utilities -description: +description: Essential utilities for using paymasters on ZKsync Era +tags: ["zksync", "paymaster", "utilities", "go", "sdk"] --- The [paymaster utilities library](https://github.com/zksync-sdk/zksync2-go/blob/main/utils/paymaster.go) contains -essential utilities for using paymasters on ZKsync Era. +essential utilities for using paymasters on ZKsync Era. These utilities facilitate the integration and use of +paymaster contracts, providing functions and interfaces to encode inputs and create paymaster parameters. ## Contract interfaces diff --git a/content/sdk/20.go/types/00.intro.md b/content/sdk/20.go/02.api/05.types/00.intro.md similarity index 100% rename from content/sdk/20.go/types/00.intro.md rename to content/sdk/20.go/02.api/05.types/00.intro.md diff --git a/content/sdk/20.go/types/04.types.md b/content/sdk/20.go/02.api/05.types/04.types.md similarity index 100% rename from content/sdk/20.go/types/04.types.md rename to content/sdk/20.go/02.api/05.types/04.types.md diff --git a/content/sdk/20.go/02.api/_dir.yml b/content/sdk/20.go/02.api/_dir.yml new file mode 100644 index 00000000..04d91e0c --- /dev/null +++ b/content/sdk/20.go/02.api/_dir.yml @@ -0,0 +1 @@ +title: API diff --git a/content/sdk/20.go/04.accounts.md b/content/sdk/20.go/04.accounts.md deleted file mode 100644 index d20f43f5..00000000 --- a/content/sdk/20.go/04.accounts.md +++ /dev/null @@ -1,2524 +0,0 @@ ---- -title: Accounts -description: ---- - -## Overview - -The `accounts` package provides abstractions that wrap operations that interact with an account. An account typically -contains a private key, allowing it to sign various types of payloads. There are the following interfaces that provide -account operations for different purposes: - -- `Signer` provides support for signing EIP-712 transactions as well as other types of transactions supported by - [`types.Signer`](https://pkg.go.dev/github.com/ethereum/go-ethereum@v1.12.0/core/types#Signer). -- `AdapterL1` is associated with an account and provides common operations on the L1 network - for the associated account. -- `AdapterL2` is associated with an account and provides common operations on the L2 network for the - associated account. -- `Deployer` is associated with an account and provides deployment of smart contracts and smart accounts on the L2 - network for the associated account. -- `Adapter` consists of `AdapterL1`, `AdapterL2`, and `Deployer` interfaces. - -There are the following objects that provide account operations: - -- `BaseSigner` implements the `Signer` interface. -- `WalletL1` implements the `AdapterL1` interface. -- `WalletL2` implements the `AdapterL2` interface. -- `BaseDeployer` implements the `Deployer` interface. -- `Wallet` implements the `Adapter` interface. -- `SmartAccount` which provides better support for account abstraction. There are following factory methods: - - `NewECDSASmartAccount`: uses a single ECDSA key for signing payload. - - `NewMultisigECDSASmartAccount`: uses multiple ECDSA keys for signing payloads. - -In most cases, `Wallet` should be used because it provides all the necessary operations. Other objects and interfaces -are separated to make the SDK more flexible and extensible. - -## `BaseSigner` - -### `Init` - -Creates a new instance of `BaseSigner` based on the provided mnemonic phrase. - -```go -func NewBaseSignerFromMnemonic(mnemonic string, chainId int64) (*BaseSigner, error) -``` - -Creates a new instance of `BaseSigner` based on the provided mnemonic phrase and account ID. - -```go -func NewBaseSignerFromMnemonicAndAccountId(mnemonic string, accountId uint32, chainId int64) (*BaseSigner, error) -``` - -Creates a new instance of BaseSigner based on the provided raw private key. - -```go -func NewBaseSignerFromRawPrivateKey(rawPk []byte, chainId int64) (*BaseSigner, error) -``` - -Creates an instance of Signer with a randomly generated private key. - -```go -func NewRandomBaseSigner(chainId int64) (*BaseSigner, error) -``` - -### `Address` - -Returns the address associated with the signer. - -```go -Address() common.Address -``` - -### `Domain` - -Returns the EIP-712 domain used for signing. - -```go -Domain() *eip712.Domain -``` - -### `PrivateKey` - -Returns the private key associated with the signer. - -```go -PrivateKey() *ecdsa.PrivateKey -``` - -Signs the given hash using the signer's private key and returns the signature. The hash should be the 32-byte hash -of the data to be signed. - -### `SignHash` - -```go -SignHash(msg []byte) ([]byte, error) -``` - -### `SignTypeData` - -Signs the given EIP-712 typed data using the signer's private key and returns the signature. The domain parameter -is the EIP-712 domain separator, and the data parameter is the EIP-712 typed data. - -```go -SignTypedData(d *eip712.Domain, data eip712.TypedData) ([]byte, error) -``` - -## `WalletL1` - -### `Init` - -Creates an instance of WalletL1 associated with the account provided by the raw private key. - -```go -func NewWalletL1(rawPrivateKey []byte, clientL1 *ethclient.Client, clientL2 *clients.Client) (*WalletL1, error -``` - -Creates an instance of WalletL1 associated with the account provided by the signer. - -```go -NewWalletL1FromSigner(signer *Signer, clientL1 *ethclient.Client, clientL2 *clients.Client) (*WalletL1, error) -``` - -#### Example - -```go -PrivateKey := os.Getenv("PRIVATE_KEY") -ZkSyncEraProvider := "https://sepolia.era.zksync.dev" -EthereumProvider := "https://rpc.ankr.com/eth_sepolia" - -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -ethClient, err := ethclient.Dial(EthereumProvider) -if err != nil { - log.Panic(err) -} -defer ethClient.Close() - -wallet, err := accounts.NewWalletL1(common.Hex2Bytes(PrivateKey), &client, ethClient) -if err != nil { - log.Panic(err) -} -``` - -### `MainContract` - -Returns the ZKsync L1 smart contract. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------- | -| `ctx` | `context.Context` | Context. | - -```go -MainContract(ctx context.Context) (*zksync.IZkSync, error) -``` - -#### Example - -```go -mainContract, err := wallet.MainContract(context.Background()) -if err != nil { - log.Panic(err) -} -``` - -### `BridgehubContract` - -Returns the Bridgehub L1 smart contract. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------- | -| `ctx` | `context.Context` | Context. | - -```go -BridgehubContract(_ context.Context) (*bridgehub.IBridgehub, error) -``` - -#### Example - -```go -bridgehub, err := wallet.BridgehubContract(context.Background()) -if err != nil { - log.Panic(err) -} -``` - -### `L1BridgeContracts` - -Returns L1 bridge contracts. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------- | -| `ctx` | `context.Context` | Context. | - -```go -L1BridgeContracts(ctx context.Context) (*zkTypes.L1BridgeContracts, error) -``` - -#### Example - -```go -contracts, err := wallet.L1BridgeContracts(context.Background()) -if err != nil { - log.Panic(err) -} -``` - -### `BaseToken` - -Returns the address of the base token on L1. - -#### Inputs - -| Parameter | Type | Description | -|-----------|----------------------------------------------------------| ----------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | - -```go -BaseToken(opts *CallOpts) (common.Address, error) -``` - -#### Example - -```go -baseToken, err := wallet.BaseToken(nil) -if err != nil { - log.Panic(err) -} -fmt.Println("Base token: ", baseToken) -``` - -### `IsEthBasedChain` - -Returns whether the chain is ETH-based. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------- | -| `ctx` | `context.Context` | Context. | - -```go -IsEthBasedChain(ctx context.Context) (bool, error) -``` - -#### Example - -```go -isEthBased, err := wallet.IsEthBasedChain(context.Background()) -if err != nil { - log.Panic(err) -} -fmt.Println("Is ETH-based chain: ", isEthBased) -``` - -### `BalanceL1` - -Returns the balance of the specified token on L1 that can be either ETH or any ERC20 token. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------------ | -------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | -| `token` | `common.Address` | Token address. | - -```go -BalanceL1(opts *CallOpts, token common.Address) (*big.Int, error) -``` - -#### Example - -```go -balance, err := wallet.BalanceL1(nil, utils.EthAddress) -if err != nil { - log.Panic(err) -} -fmt.Println("Balance: ", balance) -``` - -### `AllowanceL1` - -Returns the amount of approved tokens for a specific L1 bridge. - -#### Inputs - -| Parameter | Type | Description | -| --------------- | ------------------------------------------------ | --------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | -| `token` | `common.Address` | Token address. | -| `bridgeAddress` | `common.Address` | Bridge address. | - -```go -AllowanceL1(opts *CallOpts, token common.Address, bridgeAddress common.Address) (*big.Int, error) -``` - -#### Example - -```go -// The Crown token on testnet -TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") - -contracts, err := client.BridgeContracts(context.Background()) -if err != nil { - log.Panic(err) -} -bridgeAllowance, err := wallet.AllowanceL1(nil, TokenAddress, contracts.L1Erc20DefaultBridge) -if err != nil { - log.Panic(err) -} -fmt.Println("Bridge allowance: ", bridgeAllowance) -``` - -### `L2TokenAddress` - -Returns the corresponding address on the L2 network for the token on the L1 network. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------------- | -| `ctx` | `context.Context` | Context. | -| `token` | `common.Address` | L1 token address. | - -```go -L2TokenAddress(ctx context.Context, token common.Address) (common.Address, error) -``` - -#### Example - -```go -l1DAI := common.HexToAddress("0x5C221E77624690fff6dd741493D735a17716c26B") -l2DAI, err := wallet.L2TokenAddress(context.Background(), l1DAI) -if err != nil { - log.Panic(err) -} -fmt.Println("L2 DAI address: ", l2DAI) -``` - -### `ApproveERC20` - -Approves the specified amount of tokens for the specified L1 bridge. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------------- | -| `ctx` | `context.Context` | Context. | -| `token` | `common.Address` | L1 token address. | -| `amount` | `*big.Int` | Approval amount. | - -```go -ApproveERC20(auth *TransactOpts, token common.Address, amount *big.Int, bridgeAddress common.Address) (*types.Transaction, error) -``` - -#### Example - -```go -// The Crown token on testnet -TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") - -contracts, err := client.BridgeContracts(context.Background()) -if err != nil { - log.Panic(err) -} -tx, err := wallet.ApproveERC20(nil, TokenAddress, contracts.L1Erc20DefaultBridge) -if err != nil { - log.Panic(err) -} -fmt.Println("Tx: ", tx.Hash()) -``` - -### `BaseCost` - -Returns base cost for L2 transaction. - -#### Inputs - -| Parameter | Type | Description | -| ------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | -| `gasLimit` | `*big.Int` | The gasLimit for the the L2 contract call. | -| `gasPerPubdataByte` | `*big.Int` | The L2 gas price for each published L1 calldata byte. | -| `gasPrice` | `*big.Int` (optional) | The L1 gas price of the L1 transaction that will send the request for an execute call. | - -```go -BaseCost(opts *CallOpts, gasLimit, gasPerPubdataByte, gasPrice *big.Int) (*big.Int, error) -``` - -#### Example - -```go -gasPrice, err := client.SuggestGasPrice(context.Background()) -if err != nil { - log.Panic(err) -} - -baseCost, err := wallet.BaseCost(nil, big.NewInt(9000), utils.RequiredL1ToL2GasPerPubdataLimit, gasPrice) -if err != nil { - log.Panic(err) -} -fmt.Println("Base cost: ", baseCost) -``` - -### `DepositAllowanceParams` - -Returns the parameters for the approval token transaction based on the deposit token and amount. -Some deposit transactions require multiple approvals. Existing allowance for the bridge is not checked; -allowance is calculated solely based on the specified amount. - -#### Inputs - -| Parameter | Type | Description | -|---------------------| ---------------------------------------- | -------------------------------------------------------------------------------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | -| `msg` | [`DepositCallMsg`](/sdk/go/types/accounts#depositcallmsg) | Deposit call parameters. | - -```go -DepositAllowanceParams(opts *CallOpts, msg DepositCallMsg) ([]struct { - Token common.Address - Allowance *big.Int -}, error) -``` - -#### Example - -Get allowance parameters for depositing token on ETH-based chain. - -```go -msg := accounts.DepositCallMsg{ - Token: common.HexToAddress(""), - To: Receiver, - Amount: big.NewInt(5), -} - -allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) -if err != nil { - log.Panic(err) -} -bridgeContracts, err := client.BridgeContracts(context.Background()) -if err != nil { - log.Panic(err) -} -approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) -if err != nil { - log.Panic(err) -} -_, err = bind.WaitMined(context.Background(), ethClient, approveTx) -if err != nil { - log.Panic(err) -} -``` - -Get allowance parameters for depositing ETH on non-ETH-based chain. - -```go -msg := accounts.DepositCallMsg{ - Token: utils.LegacyEthAddress, - To: Receiver, - Amount: big.NewInt(7_000_000_000), -} - -allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) -if err != nil { - log.Panic(err) -} -bridgeContracts, err := client.BridgeContracts(context.Background()) -if err != nil { - log.Panic(err) -} -approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) -if err != nil { - log.Panic(err) -} -_, err = bind.WaitMined(context.Background(), ethClient, approveTx) -if err != nil { - log.Panic(err) -} -``` - -Get allowance parameters for depositing base token on non-ETH-based chain. - -```go -token, err := wallet.BaseToken(nil) -if err != nil { - log.Panic(err) -} - -msg := accounts.DepositCallMsg{ - Token: token, - To: Receiver, - Amount: big.NewInt(7_000_000_000), -} - -allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) -if err != nil { - log.Panic(err) -} -bridgeContracts, err := client.BridgeContracts(context.Background()) -if err != nil { - log.Panic(err) -} -approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) -if err != nil { - log.Panic(err) -} -_, err = bind.WaitMined(context.Background(), ethClient, approveTx) -if err != nil { - log.Panic(err) -} -``` - -Get allowance parameters for depositing non-base token on non-ETH-based chain. - -```go -msg := accounts.DepositCallMsg{ - Token: common.HexToAddress(""), - To: Receiver, - Amount: big.NewInt(5), -} - -allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) -if err != nil { - log.Panic(err) -} -bridgeContracts, err := client.BridgeContracts(context.Background()) -if err != nil { - log.Panic(err) -} -approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) -if err != nil { - log.Panic(err) -} -_, err = bind.WaitMined(context.Background(), ethClient, approveTx) -if err != nil { - log.Panic(err) -} -approveTx, err = wallet.ApproveERC20(nil, allowanceParams[1].Token, allowanceParams[1].Allowance, bridgeContracts.L1SharedBridge) -if err != nil { - log.Panic(err) -} -_, err = bind.WaitMined(context.Background(), ethClient, approveTx) -if err != nil { - log.Panic(err) -} -``` - -```go -ZkSyncEraProvider := "https://testnet.era.zksync.dev" - -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -gasPrice, err := client.SuggestGasPrice(context.Background()) -if err != nil { - log.Panic(err) -} - -baseCost, err := wallet.BaseCost(nil, big.NewInt(9000), utils.RequiredL1ToL2GasPerPubdataLimit, gasPrice) -if err != nil { - log.Panic(err) -} -fmt.Println("Base cost: ", baseCost) -``` - -### `Deposit` - -Transfers the specified token from the associated account on the L1 network to the target account on the L2 network. -The token can be either ETH or any ERC20 token. For ERC20 tokens, enough approved tokens must be associated with the -specified L1 bridge (default one or the one defined in `BridgeAddress`). In this case, depending on is the chain -ETH-based or not `ApproveERC20` or `ApproveBaseERC20` can be enabled to perform token approval. -to perform token approval. If there are already enough approved tokens for the L1 bridge, token approval will be -skipped. To check the amount of approved tokens for a specific bridge, use the [`AllowanceL1`](#allowancel1) method. - -#### Inputs - -| Parameter | Type | Description | -| --------- | --------------------------------------------------------- |--------------------------------| -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`DepositTransaction`](/sdk/go/types/accounts#deposittransaction) | Deposit transaction parameters.| - -```go -Deposit(auth *TransactOpts, tx DepositTransaction) (*types.Transaction, error) -``` - -#### Example - -Deposit ETH on ETH-based chain. - -```go -tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ - To: wallet.Address(), - Token: utils.LegacyEthAddress, - Amount: amount, - RefundRecipient: wallet.Address(), -}) -if err != nil { - log.Panic(err) -} - -l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) -if err != nil { - log.Panic(err) -} - -l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) -if err != nil { - log.Panic(err) -} - -l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) -if err != nil { - log.Panic(err) -} -``` - -Deposit token on ETH-based chain. - -```go -tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ - To: wallet.Address(), - Token: L1Dai, - Amount: amount, - ApproveERC20: true, - RefundRecipient: wallet.Address(), -}) -if err != nil { - log.Panic(err) -} - -l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) -if err != nil { - log.Panic(err) -} - -l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) -if err != nil { - log.Panic(err) -} - -l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) -if err != nil { - log.Panic(err) -} -``` - -Deposit ETH on non-ETH-based chain. - -```go -tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ - To: wallet.Address(), - Token: utils.LegacyEthAddress, - Amount: amount, - ApproveBaseERC20: true, - RefundRecipient: wallet.Address(), -}) -if err != nil { - log.Panic(err) -} - -l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) -if err != nil { - log.Panic(err) -} - -l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) -if err != nil { - log.Panic(err) -} - -l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) -if err != nil { - log.Panic(err) -} -``` - -Deposit base token on non-ETH-based chain. - -```go -baseToken, err := wallet.BaseToken(nil) -if err != nil { - log.Panic(err) -} - -tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ - To: wallet.Address(), - Token: baseToken, - Amount: amount, - ApproveBaseERC20: true, - RefundRecipient: wallet.Address(), -}) -if err != nil { - log.Panic(err) -} - -l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) -if err != nil { - log.Panic(err) -} - -l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) -if err != nil { - log.Panic(err) -} - -l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) -if err != nil { - log.Panic(err) -} -``` - -Deposit non-base token on non-ETH-based chain. - -```go -tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ - To: wallet.Address(), - Token: L1Dai, - Amount: amount, - ApproveERC20: true, - ApproveBaseERC20: true, - RefundRecipient: wallet.Address(), -}) -if err != nil { - log.Panic(err) -} - -l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) -if err != nil { - log.Panic(err) -} - -l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) -if err != nil { - log.Panic(err) -} - -l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) -if err != nil { - log.Panic(err) -} -``` - -### `EstimateGasDeposit` - -Estimates the amount of gas required for a deposit transaction on L1 network. Gas of approving ERC20 token is not -included in the estimation. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------------- | ------------------------ | -| `ctx` | `context.Context` | Context. | -| `msg` | [`DepositCallMsg`](/sdk/go/types/accounts#depositcallmsg) | Deposit call parameters. | - -```go -EstimateGasDeposit(ctx context.Context, msg DepositCallMsg) (uint64, error) -``` - -#### Example - -```go -depositGas, err := wallet.EstimateGasDeposit(context.Background(), accounts.DepositCallMsg{ - To: wallet.Address(), - Token: utils.EthAddress, - Amount: big.NewInt(7_000_000_000), -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Deposit gas: ", depositGas) -``` - -### `FullRequiredDepositFee` - -Retrieves the full needed ETH fee for the deposit on both L1 and L2 networks. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------------- | ------------------------ | -| `ctx` | `context.Context` | Context. | -| `msg` | [`DepositCallMsg`](/sdk/go/types/accounts#depositcallmsg) | Deposit call parameters. | - -```go -FullRequiredDepositFee(ctx context.Context, msg DepositCallMsg) (*FullDepositFee, error) -``` - -#### Example - -```go -fee, err := wallet.FullRequiredDepositFee(context.Background(), accounts.DepositCallMsg{ - To: wallet.Address(), - Token: utils.EthAddress, - Amount: big.NewInt(7_000_000_000), -}) -if err != nil { - log.Panic(err) -} -fmt.Printf("Fee: %+v\n", fee) -``` - -### `FinalizeWithdraw` - -Proves the inclusion of the L2 -> L1 withdrawal message. - -#### Inputs - -| Parameter | Type | Description | -| ---------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `withdrawalHash` | `common.Hash` | Hash of the L2 transaction where the withdrawal was initiated. | -| `index` | `int` | In case there were multiple withdrawals in one transaction, you may pass an index of the withdrawal you want to finalize. | - -```go -FinalizeWithdraw(auth *TransactOpts, withdrawalHash common.Hash, index int) (*types.Transaction, error) -``` - -#### Example - -```go -withdrawalHash := common.HexToHash("") -finalizeWithdrawTx, err := wallet.FinalizeWithdraw(nil, withdrawalHash, 0) -if err != nil { - log.Panic(err) -} -fmt.Println("Finalize withdraw transaction: ", finalizeWithdrawTx.Hash()) -``` - -### `IsWithdrawFinalized` - -Checks if the withdrawal finalized on L1 network. - -#### Inputs - -| Parameter | Type | Description | -| ---------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | -| `withdrawalHash` | `common.Hash` | Hash of the L2 transaction where the withdrawal was initiated. | -| `index` | `int` | In case there where multiple withdrawals in one transaction, you may pass an index of the withdrawal you want to finalize. | - -```go -IsWithdrawFinalized(opts *CallOpts, withdrawalHash common.Hash, index int) (bool, error) -``` - -#### Example - -```go -withdrawalHash := common.HexToHash("") -isFinalized, err := wallet.IsWithdrawFinalized(nil, withdrawalHash, 0) -if err != nil { - log.Panic(err) -} -fmt.Println("Is withdrawal finalized: ", isFinalized) -``` - -### `ClaimFailedDeposit` - -Withdraws funds from the initiated deposit, which failed when finalizing on L2. If the deposit L2 transaction has -failed, it sends an L1 transaction calling ClaimFailedDeposit method of the L1 bridge, which results in returning -L1 tokens back to the depositor, otherwise throws the error. - -#### Inputs - -| Parameter | Type | Description | -| ------------- | --------------------------------------------------------- | ---------------------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `depositHash` | `common.Hash` | The L2 transaction hash of the failed deposit. | - -```go -ClaimFailedDeposit(auth *TransactOpts, depositHash common.Hash) (*types.Transaction, error) -``` - -#### Example - -```go -failedDepositL2Hash := common.HexToHash("") -cfdTx, err := wallet.ClaimFailedDeposit(nil, failedDepositL2Hash) -if err != nil { - log.Panic(err) -} -fmt.Println("ClaimFailedDeposit hash: ", cfdTx.Hash) -``` - -### `RequestExecute` - -Request execution of L2 transaction from L1. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------------------------------------------------------------- | --------------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`RequestExecuteTransaction`](/sdk/go/types/accounts#requestexecutetransaction) | Request execute transaction parameters. | - -```go -RequestExecute(auth *TransactOpts, tx RequestExecuteTransaction) (*types.Transaction, error) -``` - -#### Example - -```go -contractAddress := common.HexToAddress("") -requestExecuteTx, err := wallet.RequestExecute(nil, accounts.RequestExecuteTransaction{ - ContractAddress: contractAddress, - L2Value: big.NewInt(7_000_000_000), - L2GasLimit: big.NewInt(90_000), - GasPerPubdataByte: utils.RequiredL1ToL2GasPerPubdataLimit, - RefundRecipient: to, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Request execute tx: ", requestExecuteTx.Hash()) -``` - -### `EstimateGasRequestExecute` - -Estimates the amount of gas required for a request execute transaction. - -#### Inputs - -| Parameter | Type | Description | -| --------- | --------------------------------------------------------------- | -------------------------------- | -| `ctx` | `context.Context` | Context. | -| `msg` | [`RequestExecuteCallMsg`](/sdk/go/types/accounts#requestexecutecallmsg) | Request execute call parameters. | - -```go -EstimateGasRequestExecute(ctx context.Context, msg RequestExecuteCallMsg) (uint64, error) -``` - -#### Example - -```go -contractAddress := common.HexToAddress("") -gas, err := wallet.EstimateGasRequestExecute(context.Background(), accounts.RequestExecuteCallMsg{ - ContractAddress: contractAddress, - L2Value: big.NewInt(7_000_000_000), - L2GasLimit: big.NewInt(90_000), - GasPerPubdataByte: utils.RequiredL1ToL2GasPerPubdataLimit, - RefundRecipient: to, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Gas: ", gas) -``` - -### `RequestExecuteAllowanceParams` - -Returns the parameters for the approval token transaction based on the request execute transaction. -Existing allowance for the bridge is not checked; allowance is calculated solely based on the specified transaction. - -#### Inputs - -| Parameter | Type | Description | -| --------- | --------------------------------------------------------------- | -------------------------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | -| `msg` | [`RequestExecuteCallMsg`](/sdk/go/types/accounts#requestexecutecallmsg) | Request execute call parameters. | - -```go -RequestExecuteAllowanceParams(opts *CallOpts, msg RequestExecuteCallMsg) (AllowanceParams, error) -``` - -#### Example - -```go -msg := accounts.RequestExecuteCallMsg{ - ContractAddress: wallet.Address(), - L2Value: big.NewInt(7_000_000_000), - Value: big.NewInt(0), -} -allowanceParams, err := wallet.RequestExecuteAllowanceParams(nil, msg) -if err != nil { - log.Panic(err) -} - -bridgeContracts, err := client.BridgeContracts(context.Background()) -if err != nil { - log.Panic(err) -} - -approveTx, err := wallet.ApproveERC20(nil, allowanceParams.Token, allowanceParams.Allowance, bridgeContracts.L1SharedBridge) -if err != nil { - log.Panic(err) -} - -_, err = bind.WaitMined(context.Background(), ethClient, approveTx) -if err != nil { - log.Panic(err) -} -``` - -### `EstimateCustomBridgeDepositL2Gas` - -Used by [`EstimateDefaultBridgeDepositL2Gas`](#estimatedefaultbridgedepositl2gas) to estimate L2 gas -required for token bridging via a custom ERC20 bridge. - -::callout{icon="i-heroicons-information-circle" color="blue"} -See the [default bridges documentation](https://docs.zksync.io/build/developer-reference/bridging-assets#default-bridges) -:: - -#### Inputs - -| Parameter | Type | Description | -| ------------------- | --------------------------- | -------------------------------- | -| `ctx` | `context.Context` | Context. | -| `l1BridgeAddress` | `common.Address` | L1 bridge address. | -| `l2BridgeAddress` | `common.Address` | L2 bridge address. | -| `token` | `common.Address` | Token address. | -| `amount` | `*big.Int` | Deposit amount. | -| `to` | `common.Address` | Recipient address. | -| `bridgeData` | `[]byte` | Bridge data. | -| `from` | `common.Address` (optional) | Sender address. | -| `gasPerPubdataByte` | `*big.Int` (optional) | Current gas per byte of pubdata. | - -```go -EstimateCustomBridgeDepositL2Gas(ctx context.Context, l1BridgeAddress, l2BridgeAddress, token common.Address, - amount *big.Int, to common.Address, bridgeData []byte, from common.Address, gasPerPubdataByte *big.Int) (uint64, error) -``` - -#### Example - -```go -L1BridgeAddress := common.HexToAddress("") -Token := common.HexToAddress("") -From := common.HexToAddress("") -To := common.HexToAddress("") - - -bridge, err := l1bridge.NewIL1Bridge(L1BridgeAddress, ethClient) -if err != nil { - log.Panic(err) -} -l2BridgeAddress, err := bridge.L2Bridge(nil) -if err != nil { - log.Panic(err) -} -customBridgeData, err := utils.Erc20DefaultBridgeData(Token, ethClient) -if err != nil { - log.Panic(err) -} - -gas, err := wallet1.EstimateCustomBridgeDepositL2Gas(context.Background(), L1BridgeAddress, l2BridgeAddress, Token, - big.NewInt(7), To, customBridgeData, From, utils.RequiredL1ToL2GasPerPubdataLimit) -if err != nil { - log.Panic(err) -} -fmt.Println("L2 gas: ", gas) -``` - -### `EstimateDefaultBridgeDepositL2Gas` - -Returns an estimation of L2 gas required for token bridging via the default ERC20 bridge. - -::callout{icon="i-heroicons-information-circle" color="blue"} -See the [default bridges documentation](https://docs.zksync.io/build/developer-reference/bridging-assets#default-bridges) -:: - -#### Inputs - -| Parameter | Type | Description | -| ------------------- | --------------------------- | -------------------------------- | -| `ctx` | `context.Context` | Context. | -| `token` | `common.Address` | Token address. | -| `amount` | `*big.Int` | Deposit amount. | -| `to` | `common.Address` | Recipient address. | -| `from` | `common.Address` (optional) | Sender address. | -| `gasPerPubdataByte` | `*big.Int` (optional) | Current gas per byte of pubdata. | - -```go -EstimateDefaultBridgeDepositL2Gas(ctx context.Context, token common.Address, amount *big.Int, - to, from common.Address, gasPerPubdataByte *big.Int) (uint64, error) -``` - -#### Example - -```go -Token := common.HexToAddress("") -From := common.HexToAddress("") -To := common.HexToAddress("") -gas, err := wallet1.EstimateDefaultBridgeDepositL2Gas( - context.Background(), Token, big.NewInt(7), To, From, utils.RequiredL1ToL2GasPerPubdataLimit, -) -if err != nil { - log.Panic(err) -} -fmt.Println("L2 gas: ", gas) -``` - -## `WalletL2` - -### `Init` - -Creates an instance of `WalletL2` associated with the account provided by the raw private key. - -```go -func NewWalletL2(rawPrivateKey []byte, client *clients.Client) (*WalletL2, error) -``` - -Creates an instance of `WalletL2`. The `client` can be optional; if it is not provided, only -`SignTransaction`, `Address`, `Signer` can be performed, as the rest of the functionalities -require communication to the network. - -```go -func NewWalletL2FromSigner(signer *Signer, client *clients.Client) (*WalletL2, error) -``` - -#### Example - -```go -PrivateKey := os.Getenv("PRIVATE_KEY") -ZkSyncEraProvider := "https://testnet.era.zksync.dev" - -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client) -if err != nil { - log.Panic(err) -} - -``` - -### `Address` - -Returns the address of the associated account. - -```go -Address() common.Address -``` - -#### Example - -```go -fmt.Println("Address: ", wallet.Address()) -``` - -### `Signer` - -Returns the signer of the associated account. - -```go -Signer() Signer -``` - -#### Example - -```go -fmt.Printf("Signer %+v\n", wallet.Signer()) -``` - -### `Balance` - -Returns the balance of the specified token that can be either ETH or any ERC20 token. The block number can be `nil`, -in which case the balance is taken from the latest known block. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------------- | -| `ctx` | `context.Context` | Context. | -| `token` | `common.Address` | L2 token address. | -| `at` | `*big.Int` | Block number. | - -```go -Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error) -``` - -#### Example - -```go -balance, err := wallet.Balance(context.Background(), utils.EthAddress, nil) -if err != nil { - log.Panic(err) -} -fmt.Println("Balance: ", balance) -``` - -### `AllBalances` - -Returns all balances for confirmed tokens given by an associated account. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------- | -| `ctx` | `context.Context` | Context. | - -```go -AllBalances(ctx context.Context) (map[common.Address]*big.Int, error) -``` - -#### Example - -```go -balances, err := wallet.AllBalances(context.Background()) -if err != nil { - log.Panic(err) -} -fmt.Printf("Balances: %+v\n", balances) -``` - -### `L2BridgeContracts` - -Returns L2 bridge contracts. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------- | -| `ctx` | `context.Context` | Context. | - -```go -L2BridgeContracts(ctx context.Context) (*zkTypes.L2BridgeContracts, error) -``` - -#### Example - -```go -contracts, err := wallet.L2BridgeContracts(context.Background()) -if err != nil { - log.Panic(err) -} -``` - -### `DeploymentNonce` - -Returns the deployment nonce of the account. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------------ | ------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | - -```go -func (a *WalletL2) DeploymentNonce(opts *CallOpts) (*big.Int, error) -``` - -#### Example - -```go -deploymentNonce, err := wallet.DeploymentNonce(nil) -if err != nil { - log.Panic(err) -} -``` - -### `IsBaseToken` - -Returns whether the token is the base token. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- |----------------| -| `ctx` | `context.Context` | Context. | -| `token` | `common.Address` | Token address. | - -```go -IsBaseToken(ctx context.Context, token common.Address) (bool, error) -``` - -#### Example - -```go -isBaseToken, err := wallet.IsBaseToken( - context.Background(), - common.HexToAddress("0x5C221E77624690fff6dd741493D735a17716c26B") -) -if err != nil { - log.Panic(err) -} -fmt.Println("Is base token: ", isBaseToken) -``` - -### `Withdraw` - -Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network -to the target account on L1 network. - -#### Inputs - -| Parameter | Type | Description | -| --------- | --------------------------------------------------------------- | ---------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`WithdrawalTransaction`](/sdk/go/types/accounts#withdrawaltransaction) | Withdrawal transaction parameters. | - -```go -Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (*types.Transaction, error) -``` - -#### Example - -```go -tx, err := wallet.Withdraw(nil, accounts.WithdrawalTransaction{ - To: wallet.Address(), - Amount: big.NewInt(1_000_000_000_000_000_000), - Token: utils.EthAddress, -}) -if err != nil { - panic(err) -} -fmt.Println("Withdraw transaction: ", tx.Hash()) -``` - -### `EstimateGasWithdraw` - -Estimates the amount of gas required for a withdrawal transaction. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------------------- | --------------------------- | -| `ctx` | `context.Context` | Context. | -| `msg` | [`WithdrawalCallMsg`](/sdk/go/types/accounts#withdrawalcallmsg) | Withdrawal call parameters. | - -```go -EstimateGasWithdraw(ctx context.Context, msg WithdrawalCallMsg) (uint64, error) -``` - -#### Example - -```go -gas, err := wallet.EstimateGasWithdraw(context.Background(), accounts.WithdrawalCallMsg{ - To: wallet.Address(), - Amount: big.NewInt(7_000_000), - Token: utils.EthAddress, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Gas: ", gas) -``` - -### `Transfer` - -Moves the ETH or any ERC20 token from the associated account to the target account. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------------------------------------------------- | -------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`TransferTransaction`](/sdk/go/types/accounts#transfertransaction) | Transfer transaction parameters. | - -```go -Transfer(auth *TransactOpts, tx TransferTransaction) (*types.Transaction, error) -``` - -#### Example - -```go -tx, err := wallet.Transfer(nil, accounts.TransferTransaction{ - To: common.HexToAddress(""), - Amount: big.NewInt(7_000_000_000), - Token: utils.EthAddress, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Transaction: ", tx.Hash()) -``` - -### `EstimateGasTransfer` - -Estimates the amount of gas required for a transfer transaction. - -#### Inputs - -| Parameter | Type | Description | -| --------- | --------------------------------------------------- | ------------------------- | -| `ctx` | `context.Context` | Context. | -| `msg` | [`TransferCallMsg`](/sdk/go/types/accounts#transfercallmsg) | Transfer call parameters. | - -```go -EstimateGasTransfer(ctx context.Context, msg TransferCallMsg) (uint64, error) -``` - -#### Example - -```go -gas, err := wallet.EstimateGasTransfer(context.Background(), accounts.TransferCallMsg{ - To: common.HexToAddress(""), - Amount: big.NewInt(7_000_000_000), - Token: utils.EthAddress, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Gas: ", gas) -``` - -### `CallContract` - -Executes a message call for EIP-712 transaction, which is directly executed in the VM of the node, but never mined -into the blockchain. - -#### Inputs - -| Parameter | Type | Description | -| ------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `ctx` | `context.Context` | Context. | -| `msg` | [`CallMsg`](/sdk/go/types/accounts#callmsg) | Contains parameters for contract call using EIP-712 transaction. | -| `blockNumber` | `*big.Int` (optional) | Selects the block height at which the call runs. It can be `nil`, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available. | - -```go -CallContract(ctx context.Context, msg CallMsg, blockNumber *big.Int) ([]byte, error) -``` - -#### Example - -```go -// The Crown token on testnet -TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") - -tokenAbi, err := erc20.IERC20MetaData.GetAbi() -if err != nil { - log.Panic(err) -} -symbolCalldata, err := tokenAbi.Pack("symbol") -if err != nil { - log.Panic(err) -} - -result, err := wallet.CallContract(context.Background(), types.CallMsg{ - CallMsg: ethereum.CallMsg{ - To: &TokenAddress, - Data: symbolCalldata, - }, -}, nil) -if err != nil { - log.Panic(err) -} -unpack, err := tokenAbi.Unpack("symbol", result) -if err != nil { - log.Panic(err) -} -symbol := *abi.ConvertType(unpack[0], new(string)).(*string) -fmt.Println("Symbol: ", symbol) -``` - -### PopulateTransaction - -Designed for users who prefer a simplified approach by providing only the necessary data to create a valid -[EIP-712 transaction](/sdk/go/types/types#transaction712). The only required fields are `Transaction.To` and either -`Transaction.Data` or `Transaction.Value` (or both, if the method is payable). -Any other fields that are not set will be prepared by this method. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------- | ----------------------- | -| `ctx` | `context.Context` | Context. | -| `tx` | [`Transaction`](/sdk/go/types/accounts#transaction) | Transaction parameters. | - -```go -PopulateTransaction(ctx context.Context, tx Transaction) (*zkTypes.Transaction712, error) -``` - -#### Example - -```go -// The Crown token on testnet -TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") -// Paymaster for Crown token on testnet -PaymasterAddress := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46") -ReceiptAddress := common.HexToAddress("0xa61464658AfeAf65CccaaFD3a512b69A83B77618") - -abi, err := erc20.IERC20MetaData.GetAbi() -if err != nil { - log.Panic(err) -} - -// Encode transfer function from token contract -calldata, err := abi.Pack("transfer", ReceiptAddress, big.NewInt(7)) -if err != nil { - log.Panic(err) -} - -preparedTx, err := wallet.PopulateTransaction(context.Background(), &accounts.Transaction{ - To: &TokenAddress, - Data: calldata, -}) -fmt.Printf("Prepared tx: %+v\n", preparedTx) -``` - -### `SignTransaction` - -Returns a signed transaction that is ready to be broadcast to the network. The input transaction must be a valid -transaction with all fields having appropriate values. To obtain a valid transaction, you can use the -[`PopulateTransaction`](#populatetransaction) method. - -#### Inputs - -| Parameter | Type | Description | -| --------- |----------------------------------------------------------------| ------------------------------- | -| `tx` | [`zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | EIP-712 transaction parameters. | - -```go -SignTransaction(tx *zkTypes.Transaction712) ([]byte, error) -``` - -#### Example - -```go -// The Crown token on testnet -TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") -// Paymaster for Crown token on testnet -PaymasterAddress := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46") -ReceiptAddress := common.HexToAddress("0xa61464658AfeAf65CccaaFD3a512b69A83B77618") - -abi, err := erc20.IERC20MetaData.GetAbi() -if err != nil { - log.Panic(err) -} - -// Encode transfer function from token contract -calldata, err := abi.Pack("transfer", ReceiptAddress, big.NewInt(7)) -if err != nil { - log.Panic(err) -} - -preparedTx, err := wallet.PopulateTransaction(context.Background(), &accounts.Transaction{ - To: &TokenAddress, - Data: calldata, -}) - -signedTx, err := wallet.SignTransaction(preparedTx) -if err != nil { - log.Panic(err) -} -fmt.Printf("Signed tx: %+v\n", signedTx) -``` - -### `SendTransaction` - -Injects a transaction into the pending pool for execution. Any unset transaction fields are prepared using the -`PopulateTransaction` method. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------- | ----------------------- | -| `ctx` | `context.Context` | Context. | -| `tx` | [`Transaction`](/sdk/go/types/accounts#transaction) | Transaction parameters. | - -```go -SendTransaction(ctx context.Context, tx *Transaction) (common.Hash, error) -``` - -#### Example - -```go -// The Crown token on testnet -TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") -// Paymaster for Crown token on testnet -PaymasterAddress := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46") -ReceiptAddress := common.HexToAddress("0xa61464658AfeAf65CccaaFD3a512b69A83B77618") - -abi, err := erc20.IERC20MetaData.GetAbi() -if err != nil { - log.Panic(err) -} - -// Encode transfer function from token contract -calldata, err := abi.Pack("transfer", ReceiptAddress, big.NewInt(7)) -if err != nil { - log.Panic(err) -} - -// Create paymaster parameters with encoded paymaster input -paymasterParams, err := utils.GetPaymasterParams( - PaymasterAddress, - &zkTypes.ApprovalBasedPaymasterInput{ - Token: TokenAddress, - MinimalAllowance: big.NewInt(1), - InnerInput: []byte{}, - }) -if err != nil { - log.Panic(err) -} - -hash, err := wallet.SendTransaction(context.Background(), &accounts.Transaction{ - To: &TokenAddress, - Data: calldata, - Meta: &types.Eip712Meta{ - PaymasterParams: paymasterParams, - }, -}) -if err != nil { - log.Panic(err) -} - -_, err = client.WaitMined(context.Background(), hash) -if err != nil { - log.Panic(err) -} - -fmt.Println("Tx: ", hash) -``` - -## `BaseDeployer` - -### `Init` - -Creates an instance of `BaseDeployer` based on provided `AdapterL2`. - -```go -func NewBaseDeployer(adapter *AdapterL2) *BaseDeployer -``` - -### `Deploy` - -Deploys smart contract using CREATE2 method. - -#### Inputs - -| Parameter | Type | Description | -| --------- | --------------------------------------------------------- | ------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`Create2Transaction`](/sdk/go/types/accounts#create2transaction) | CREATE2 transaction parameters. | - -```go -Deploy(auth *TransactOpts, tx Create2Transaction) (common.Hash, error) -``` - -#### Example - -```go -bytecode, err := os.ReadFile("Storage.zbin") -if err != nil { - log.Panic(err) -} - -//Deploy smart contract -hash, err := wallet.Deploy(nil, accounts.Create2Transaction{Bytecode: bytecode}) -if err != nil { - panic(err) -} -fmt.Println("Transaction: ", hash) -``` - -### `DeployWithCreate` - -Deploys smart contract using CREATE method. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------------------- | ------------------------------ | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`CreateTransaction`](/sdk/go/types/accounts#createtransaction) | CREATE transaction parameters. | - -```go -DeployWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error) -``` - -#### Example - -```go -bytecode, err := os.ReadFile("Storage.zbin") -if err != nil { - log.Panic(err) -} - -//Deploy smart contract -hash, err := wallet.DeployWithCreate(nil, accounts.CreateTransaction{Bytecode: bytecode}) -if err != nil { - panic(err) -} -fmt.Println("Transaction: ", hash) -``` - -### `DeployAccount` - -Deploys smart account using CREATE2 method. - -#### Inputs - -| Parameter | Type | Description | -| --------- | --------------------------------------------------------- | ------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`Create2Transaction`](/sdk/go/types/accounts#create2transaction) | CREATE2 transaction parameters. | - -```go -DeployAccount(auth *TransactOpts, tx Create2Transaction) (common.Hash, error) -``` - -#### Example - -```go -# Crown token on testnet -TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") - -_, paymasterAbi, bytecode, err := utils.ReadStandardJson("Paymaster.json") -if err != nil { - log.Panic(err) -} - -// Encode paymaster constructor -constructor, err := paymasterAbi.Pack("", common.HexToAddress(TokenAddress)) -if err != nil { - log.Panic(err) -} - -// Deploy paymaster contract -hash, err := wallet.DeployAccount(nil, accounts.Create2Transaction{Bytecode: bytecode, Calldata: constructor}) -if err != nil { - log.Panic(err) -} -if err != nil { - log.Panic(err) -} -fmt.Println("Transaction: ", hash) - -``` - -### `DeployAccountWithCreate` - -Deploys smart account using CREATE method. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------------------- | ------------------------------ | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`CreateTransaction`](/sdk/go/types/accounts#createtransaction) | CREATE transaction parameters. | - -```go -DeployAccountWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error) -``` - -#### Example - -```go -# Crown token on testnet -TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") - -_, paymasterAbi, bytecode, err := utils.ReadStandardJson("Paymaster.json") -if err != nil { - log.Panic(err) -} - -constructor, err := paymasterAbi.Pack("", common.HexToAddress(TokenAddress)) -if err != nil { - log.Panic(err) -} - -// Deploy paymaster contract -hash, err := wallet.DeployAccountWithCreate(nil, accounts.CreateTransaction{ - Bytecode: bytecode, - Calldata: constructor, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Transaction: ", hash) -``` - -## `Wallet` - -It contains the same functions as [`WalletL1`](#walletl1), [`WalletL2`](#walletl2), and [`BaseDeployer`](#basedeployer) -since it implements the Adapter interface, and the usage of those methods is the same. - -### `Init` - -Creates an instance of `Wallet` associated with the account provided by the `rawPrivateKey`. The `clientL1` -parameters is optional; if not provided, only methods from `AdapterL2` and `Deployer` interfaces can be used, -as the rest of the functionalities require communication with the L1 network. A `Wallet` can be configured to -communicate with L1 networks by using and [`ConnectL1`](#connectl1) method. - -```go -func NewWallet(rawPrivateKey []byte, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) -``` - -Creates an instance of Wallet associated with the account provided by the signer. The `clientL2` and `clientL1` -parameters are optional; if not provided, only `SignTransaction`, `Address` and `Signer` methods can be used, -as the rest of the functionalities require communication with the network. A wallet that contains only a -signer can be configured to communicate with L2 and L1 networks by using [`Connect`](#connect) and -[`ConnectL1`](#connectl1), respectively. - -```go -func NewWalletFromSigner(signer Signer, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) -``` - -Creates a new instance of `Wallet` based on the provided mnemonic phrase. The `clientL2` and `clientL1` -parameters are optional, and can be configured with [`Connect`](#connect) and [`ConnectL1`](#connectl1), respectively. - -```go -func NewWalletFromMnemonic(mnemonic string, chainId int64, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) -``` - -Creates a new instance of `Wallet` based on the provided private key of the account and chain ID. -The `clientL2` and `clientL1` parameters are optional, and can be configured with [`Connect`](#connect) -and [`ConnectL1`](#connectl1), respectively. - -```go -func NewWalletFromRawPrivateKey(rawPk []byte, chainId int64, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) -``` - -Creates an instance of `Wallet` with a randomly generated account. The `clientL2` and `clientL1` parameters are -optional, and can be configured with [`Connect`](#connect) and [`ConnectL1`](#connectl1), respectively. - -```go -func NewRandomWallet(chainId int64, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error) -``` - -#### Example - -```go -PrivateKey := os.Getenv("PRIVATE_KEY") -ZkSyncEraProvider := "https://sepolia.era.zksync.dev" -EthereumProvider := "https://rpc.ankr.com/eth_sepolia" - -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -ethClient, err := ethclient.Dial(EthereumProvider) -if err != nil { - log.Panic(err) -} -defer ethClient.Close() - -wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, ethClient) -if err != nil { - log.Panic(err) -} - -chainID, err := client.ChainID(context.Background()) -if err != nil { - log.Panic(err) -} -wallet, err = accounts.NewRandomWallet(chainID.Int64(),nil,nil) -if err != nil { - log.Panic(err) -} -``` - -### `Connect` - -Returns a new instance of `Wallet` with the provided client for the L2 network. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ---------------------------- | ----------- | -| `client` | [`*clients.Client`](/sdk/go/clients) | L2 client. | - -```go -Connect(client *clients.Client) (*Wallet, error) -``` - -#### Example - -```go -PrivateKey := os.Getenv("PRIVATE_KEY") -ZkSyncEraProvider := "https://testnet.era.zksync.dev" - -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -chainID, err := client.ChainID(context.Background()) -if err != nil { - log.Panic(err) -} - -wallet, err := accounts.NewRandomWallet(chainID, nil, nil) -if err != nil { - log.Panic(err) -} - -// create new wallet with connection to L2 -wallet, err = wallet.Connect(&client) -if err != nil { - log.Panic(err) -} -``` - -### `ConnectL1` - -Returns a new instance of `Wallet` with the provided client for the L1 network. - -#### Inputs - -| Parameter | Type | Description | -| --------- | -------------------------------------------------------------------------------------------------- | ----------- | -| `client` | [`*ethclient.Client`](https://pkg.go.dev/github.com/ethereum/go-ethereum@v1.12.0/ethclient#Client) | L1 client. | - -```go -ConnectL1(client *ethclient.Client) (*Wallet, error) -``` - -#### Example - -```go -chainID, err := client.ChainID(context.Background()) -if err != nil { - log.Panic(err) -} - -wallet, err = accounts.NewRandomWallet(chainID, nil, nil) -if err != nil { - log.Panic(err) -} - -// create new wallet with connection to L1 -wallet, err = wallet.Connect(ðClient) -if err != nil { - log.Panic(err) -} -``` - -### `Nonce` - -Returns the account nonce of the associated account. The block number can be `nil`, in which case the nonce is taken -from the latest known block. - -#### Inputs - -| Parameter | Type | Description | -| ------------- | --------------------- | ------------- | -| `ctx` | `context.Context` | Context. | -| `blockNumber` | `*big.Int` (optional) | Block number. | - -```go -Nonce(ctx context.Context, blockNumber *big.Int) (uint64, error) -``` - -#### Example - -```go -nonce, err := wallet.Nonce(context.Background(), big.NewInt(9000)) -if err != nil { - log.Panic(err) -} -fmt.Println("Nonce: ", nonce) -``` - -### `PendingNonce` - -Returns the account nonce of the associated account in the pending state. -This is the nonce that should be used for the next transaction. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------- | -| `ctx` | `context.Context` | Context. | - -```go -PendingNonce(ctx context.Context) (uint64, error) -``` - -#### Example - -```go -nonce, err := wallet.PendingNonce(context.Background()) -if err != nil { - log.Panic(err) -} -fmt.Println("Nonce: ", nonce) -``` - -## `SmartAccount` - -A `SmartAccount` is a signer which can be configured to sign various payloads using a provided secret. -The secret can be in any form, allowing for flexibility when working with different account implementations. -The `SmartAccount` is bound to a specific address and provides the ability to define custom method for populating transactions -and custom signing method used for signing messages, typed data, and transactions. - -### `Init` - -Creates a new `SmartAccount` instance. By default, it uses [`SignPayloadWithECDSA`](/sdk/go/smart-account-utils#signpayloadwithecdsa) -as a signer and [`PopulateTransactionECDSA`](/sdk/go/smart-account-utils#populatetransactionecdsa) as a builder and -requires private key in hex format to be provided. - -#### Inputs - -| Parameter | Type | Description | -|-----------|--------------------------------------------------------------------|---------------------------------------------------------| -| `address` | `common.Address` | Account address. | -| `secret` | `interface{}` | Secret used for signing. | -| `signer` | [`*PayloadSigner`](/sdk/go/types/accounts#payloadsigner) | Function used for signing payload. | -| `builder` | [`*TransactionBuilder`](/sdk/go/types/accounts#transactionbuilder) | Function used for populating transaction. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client to connect to. Can be `nil` for offline usage. | - -```go - -func NewSmartAccount( - address common.Address, - secret interface{}, - signer *PayloadSigner, - builder *TransactionBuilder, - client *clients.BaseClient) *SmartAccount -``` - -#### Examples - -```go -privateKey := os.Getenv("PRIVATE_KEY") -address := common.HexToAddress("") -ZkSyncEraProvider := "https://sepolia.era.zksync.dev" - -client, err := clients.DialBase(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -account := accounts.NewSmartAccount( - address, - privateKey, - &accounts.SignPayloadWithECDSA, - &accounts.PopulateTransactionECDSA, -nil) -``` - -### `NewECDSASmartAccount` - -Creates a `SmartAccount` instance that uses single ECDSA key for signing payload. - -| Parameter | Type | Description | -|--------------|-----------------------------------------------------|----------------------------------------------------------| -| `address` | `common.Address` | Account address. | -| `privateKey` | `string` | The ECDSA private key. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client to connect to. Can be `nil` for offline usage. | - -```go - -func NewECDSASmartAccount(address common.Address, privateKey string, client *clients.BaseClient) *SmartAccount -``` - -#### Example - -```go -privateKey := os.Getenv("PRIVATE_KEY") -address := common.HexToAddress("") -ZkSyncEraProvider := "https://sepolia.era.zksync.dev" - -client, err := clients.DialBase(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -account := accounts.NewECDSASmartAccount(address, privateKey, client) -``` - -### `NewMultisigECDSASmartAccount` - -Creates a `SmartAccount` instance that uses multiple ECDSA keys for signing payloads. -The signature is generated by concatenating signatures created by signing with each key individually. - -| Parameter | Type | Description | -|---------------|-----------------------------------------------------|-----------------------------------------------------------| -| `address` | `common.Address` | Account address. | -| `privateKeys` | `[]string` | The list of the ECDSA private keys. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client to connect to. Can be `nil` for offline usage. | - -```go -NewMultisigECDSASmartAccount(address common.Address, privateKeys []string, client *clients.BaseClient) *SmartAccount -``` - -#### Example - -```go -privateKey1 := os.Getenv("PRIVATE_KEY1") -privateKey2 := os.Getenv("PRIVATE_KEY2") -address := common.HexToAddress("") -ZkSyncEraProvider := "https://sepolia.era.zksync.dev" - -client, err := clients.DialBase(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -account := accounts.NewMultisigECDSASmartAccount(address, []string{privateKey1, privateKey2}, client) -``` - -### `Connect` - -Creates a new instance of SmartAccount connected to a client or -detached from any provider if `nil` is provided. - -#### Inputs - -| Parameter | Type | Description | -| --------- |---------------------------------------------------|---------------------------------------------------------------------------------------------------------------| -| `client` | [`*clients.DialBase`](/sdk/go/clients#baseclient) | The client to connect the `SmartAccount` to. If `nil`, the `SmartAccount` will be detached from any provider. | - -```go -Connect(client *clients.BaseClient) *SmartAccount -``` - -#### Example - -```go -privateKey := os.Getenv("PRIVATE_KEY") -ZkSyncEraProvider := "https://testnet.era.zksync.dev" - -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -account := accounts.NewECDSASmartAccount(Address1, PrivateKey1, nil) -account = account.Connect(client) -``` - -### `Address` - -Returns the address of the associated account. - -```go -Address() common.Address -``` - -#### Example - -```go -fmt.Println("Address: ", account.Address()) -``` - -### `Balance` - -Returns the balance of the specified token that can be either ETH or any ERC20 token. The block number can be `nil`, -in which case the balance is taken from the latest known block. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------------- | -| `ctx` | `context.Context` | Context. | -| `token` | `common.Address` | L2 token address. | -| `at` | `*big.Int` | Block number. | - -```go -Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error) -``` - -#### Example - -```go -balance, err := account.Balance(context.Background(), utils.EthAddress, nil) -if err != nil { - log.Panic(err) -} -fmt.Println("Balance: ", balance) -``` - -### `AllBalances` - -Returns all balances for confirmed tokens given by an associated account. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------- | -| `ctx` | `context.Context` | Context. | - -```go -AllBalances(ctx context.Context) (map[common.Address]*big.Int, error) -``` - -#### Example - -```go -balances, err := account.AllBalances(context.Background()) -if err != nil { - log.Panic(err) -} -fmt.Printf("Balances: %+v\n", balances) -``` - -### `Nonce` - -Returns the account nonce of the associated account. The block number can be `nil`, in which case the nonce is taken -from the latest known block. - -#### Inputs - -| Parameter | Type | Description | -| ------------- | --------------------- | ------------- | -| `ctx` | `context.Context` | Context. | -| `blockNumber` | `*big.Int` (optional) | Block number. | - -```go -Nonce(ctx context.Context, blockNumber *big.Int) (uint64, error) -``` - -#### Example - -```go -nonce, err := account.Nonce(context.Background(), big.NewInt(9000)) -if err != nil { - log.Panic(err) -} -fmt.Println("Nonce: ", nonce) -``` - -### `DeploymentNonce` - -Returns the deployment nonce of the account. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------------ | ------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | - -```go -DeploymentNonce(opts *CallOpts) (*big.Int, error) -``` - -#### Example - -```go -deploymentNonce, err := account.DeploymentNonce(nil) -if err != nil { - log.Panic(err) -} -``` - -### `PopulateTransaction` - -Populates the transaction `tx` using the provided [`TransactionBuilder`](/sdk/go/types/accounts#transactionbuilder) function. -If `tx.From` is not set, it sets the value from the `Address()` method which can -be utilized in the `TransactionBuilder` function. - -#### Inputs - -| Parameter | Type | Description | -|-----------|----------------------------------------------------------|------------------------------------| -| `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be populated. | - -```go -PopulateTransaction(ctx context.Context, tx *zkTypes.Transaction712) error -``` - -#### Example - -```go -address := common.HexToAddress("") -tx := &zkTypes.Transaction712{ - To: &address, - Value: big.NewInt(7_000_000_000), -} - -err = account.PopulateTransaction(context.Background(), tx) -if err != nil { - log.Panic(err) -} -``` - -### `SignTransaction` - -Returns a signed transaction that is ready to be broadcast to -the network. The `PopulateTransaction` method is called first to ensure that all -necessary properties for the transaction to be valid have been populated. - -#### Inputs - -| Parameter | Type | Description | -|-----------|---------------------------------------------------------|------------------------------------------| -| `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be signed. | - -```go - -SignTransaction(ctx context.Context, tx *zkTypes.Transaction712) ([]byte, error) -``` - -#### Example - -```go -address := common.HexToAddress("") -signedTx, err := account.SignTransaction(context.Background(), &zkTypes.Transaction712{ - To: &address, - Value: big.NewInt(1_000_000_000_000_000_000), // 1ETH -}) -if err != nil { - log.Panic(err) -} -``` - -### `SendTransaction` - -Injects a transaction into the pending pool for execution. -The `SignTransaction` is called first to ensure transaction is properly signed. - -#### Inputs - -| Parameter | Type | Description | -|-----------|---------------------------------------------------------|------------------------------------------| -| `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be signed. | - -```go -SendTransaction(ctx context.Context, tx *zkTypes.Transaction712) (common.Hash, error) -``` - -#### Example - -```go -address := common.HexToAddress("") -txHash, err := account.SendTransaction(context.Background(), &zkTypes.Transaction712{ - To: &address, - Value: big.NewInt(1_000_000_000_000_000_000), // 1ETH -}) -if err != nil { - log.Panic(err) -} -``` - -### `SignMessage` - -Signs a message using the provided [`PayloadSigner`](/sdk/go/types/accounts#payloadsigner) function. - -#### Inputs - -| Parameter | Type | Description | -|-----------|-------------------|--------------------------------------| -| `ctx` | `context.Context` | Context. | -| `message` | `[]byte` | The message that needs to be signed. | - -```go -SignMessage(ctx context.Context, message []byte) ([]byte, error) -``` - -#### Example - -```go -signature, err := account.SignMessage(context.Background(), []byte("Hello World!")) -if err != nil { - log.Panic(err) -} -``` - -### `SignTypedData` - -signs a typed data using the provided [`PayloadSigner`](/sdk/go/types/accounts#payloadsigner) function. - -#### Inputs - -| Parameter | Type | Description | -|-------------|-----------------------|-----------------------------------------| -| `ctx` | `context.Context` | Context. | -| `typedData` | `apitypes.TypedData` | The typed data that needs to be signed. | - -```go -SignTypedData(ctx context.Context, typedData apitypes.TypedData) ([]byte, error) -``` - -#### Example - -```go -signature, err := account.SignTypedData(context.Background(), apitypes.TypedData{ - Domain: apitypes.TypedDataDomain{ - Name: "Example", - Version: "1", - ChainId: math.NewHexOrDecimal256(270), - }, - Types: apitypes.Types{ - "Person": []apitypes.Type{ - {Name: "name", Type: "string"}, - {Name: "age", Type: "uint8"}, - }, - "EIP712Domain": []apitypes.Type{ - {Name: "name", Type: "string"}, - {Name: "version", Type: "string"}, - {Name: "chainId", Type: "uint256"}, - }, - }, - PrimaryType: "Person", - Message: apitypes.TypedDataMessage{ - "name": "John", - "age": hexutil.EncodeUint64(30), - }, -}) -if err != nil { - log.Panic(err) -} -``` - -### `Withdraw` - -Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network -to the target account on L1 network. - -#### Inputs - -| Parameter | Type | Description | -| --------- | --------------------------------------------------------------- | ---------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`WithdrawalTransaction`](/sdk/go/types/accounts#withdrawaltransaction) | Withdrawal transaction parameters. | - -```go -Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (common.Hash, error) -``` - -#### Examples - -Withdraw ETH. - -```go -txHash, err := account.Withdraw(nil, accounts.WithdrawalTransaction{ - To: account.Address(), - Amount: big.NewInt(1_000_000_000_000_000_000), - Token: utils.LegacyEthAddress, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Withdraw transaction: ", txHash) -``` - -Withdraw ETH using paymaster to facilitate fee payment with an ERC20 token. - -```go -token := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F"); // Crown token which can be minted for free -paymaster := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46"); // Paymaster for Crown token - -paymasterParams, err := utils.GetPaymasterParams( - paymaster, - &zkTypes.ApprovalBasedPaymasterInput{ - Token: token, - MinimalAllowance: big.NewInt(1), - InnerInput: []byte{}, -}) -if err != nil { - log.Panic(err) -} - -txHash, err := account.Withdraw(nil, accounts.WithdrawalTransaction{ - To: account.Address(), - Amount: big.NewInt(1_000_000_000_000_000_000), - Token: utils.LegacyEthAddress, - PaymasterParams: paymasterParams, - }) -``` - -### `Transfer` - -Moves the ETH or any ERC20 token from the associated account to the target account. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------------------------------------------------- | -------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`TransferTransaction`](/sdk/go/types/accounts#transfertransaction) | Transfer transaction parameters. | - -```go -Transfer(auth *TransactOpts, tx TransferTransaction) (common.Hash, error) -``` - -#### Examples - -Transfer ETH. - -```go -txHash, err := account.Transfer(nil, accounts.TransferTransaction{ - To: Address2, - Amount: amount, - Token: utils.LegacyEthAddress, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Transaction: ", txHash) -``` - -Transfer ETH using paymaster to facilitate fee payment with an ERC20 token. - -```go -token := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F"); // Crown token which can be minted for free -paymaster := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46"); // Paymaster for Crown token - -paymasterParams, err := utils.GetPaymasterParams( - paymaster, - &zkTypes.ApprovalBasedPaymasterInput{ - Token: token, - MinimalAllowance: big.NewInt(1), - InnerInput: []byte{}, -}) -if err != nil { - log.Panic(err) -} - -txHash, err := account.Transfer(nil, accounts.TransferTransaction{ - To: Address2, - Amount: amount, - Token: utils.LegacyEthAddress, - PaymasterParams: paymasterParams, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Transaction: ", txHash) -``` From f6617425815ec2f551f5c9d7b04a51d9d10fe240 Mon Sep 17 00:00:00 2001 From: Ngozi-Txfusion Date: Sat, 6 Jul 2024 17:58:52 +0100 Subject: [PATCH 2/9] fix: update links --- content/sdk/20.go/01.guides/01.features.md | 10 +++--- .../20.go/02.api/00.clients/01.baseclient.md | 25 ++++++------- .../02.api/01.accounts/02.basedeployer.md | 16 ++++----- .../sdk/20.go/02.api/01.accounts/03.wallet.md | 2 +- .../20.go/02.api/01.accounts/04.walletl1.md | 36 +++++++++---------- .../20.go/02.api/01.accounts/05.walletl2.md | 24 ++++++------- .../02.api/01.accounts/06.smartaccount.md | 6 ++-- .../00.newecdsasmartaccount.md | 2 +- .../01.newmultisigecdsasmartaccount.md | 26 +++++++------- .../01.accounts/08.smart-account-utils.md | 16 ++++----- .../sdk/20.go/02.api/01.accounts/09.types.md | 2 +- .../20.go/02.api/03.contracts/00.contracts.md | 4 +-- .../sdk/20.go/02.api/04.utilities/00.utils.md | 4 +-- .../02.api/04.utilities/01.paymaster-utils.md | 2 +- content/sdk/20.go/02.api/05.types/00.intro.md | 19 +++++----- content/sdk/20.go/02.api/05.types/04.types.md | 9 +++-- 16 files changed, 105 insertions(+), 98 deletions(-) diff --git a/content/sdk/20.go/01.guides/01.features.md b/content/sdk/20.go/01.guides/01.features.md index 1dcb6f97..55765965 100644 --- a/content/sdk/20.go/01.guides/01.features.md +++ b/content/sdk/20.go/01.guides/01.features.md @@ -21,14 +21,14 @@ 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/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/types#callmsg) +- [`types.Transaction712`](/sdk/go/api/types/types#transaction712) +- [`accounts.CallMsg`](/sdk/go/api/types/types#callmsg) +- [`accounts.Transaction`](/sdk/go/api/types/types#transactiondetails) ## Encoding paymaster params diff --git a/content/sdk/20.go/02.api/00.clients/01.baseclient.md b/content/sdk/20.go/02.api/00.clients/01.baseclient.md index fcbc6f24..ef0c204c 100644 --- a/content/sdk/20.go/02.api/00.clients/01.baseclient.md +++ b/content/sdk/20.go/02.api/00.clients/01.baseclient.md @@ -54,7 +54,7 @@ defer wsClient.Close() Executes a log filter operation, blocking during execution, and returns all the results in one batch. This method is a replacement for `FilterLogs` because the returned `types.Log` type does not contain additional data specific to L2, -as found in [`Log`](/sdk/go/types/types#log). The `FilterLogs` method is kept in order to be compatible with `bind.ContractBackend`, +as found in [`Log`](/sdk/go/api/types/types#log). The `FilterLogs` method is kept in order to be compatible with `bind.ContractBackend`, and this method can be used, but additional L2 data won't be retrieved. #### Inputs @@ -95,7 +95,8 @@ for _, l := range zkLogs { Creates a background log filtering operation, returning a subscription immediately, which can be used to stream the found events. This method is a replacement for `SubscribeFilterLogs` because the returned `types.Log` type does not -contain additional data specific to L2, as found in [`Log`](/sdk/go/types/types#log). The `SubscribeFilterLogs` method is +contain additional data specific to L2, as found +in [`Log`](/sdk/go/api/types/types#log). The `SubscribeFilterLogs` method is kept in order to be compatible with `bind.ContractBackend`, and this method can be used, but additional L2 data won't be retrieved. @@ -105,7 +106,7 @@ won't be retrieved. | --------- | --------------------------------------------------------------------------------------------- | -------------------------- | | `ctx` | `context.Context` | Context. | | `query` | [`ethereum.FilterQuery`](https://pkg.go.dev/github.com/ethereum/go-ethereum@v1.12.0#FilterQuery) | Filter query parameters. | -| `ch` | [`chan<- zkTypes.Log`](/sdk/go/types/types#log) | Channel that receives Log. | +| `ch` | [`chan<- zkTypes.Log`](/sdk/go/api/types/types#log) | Channel that receives Log. | ```go SubscribeFilterLogsL2(ctx context.Context, query ethereum.FilterQuery, ch chan<- zkTypes.Log) (ethereum.Subscription, error) @@ -152,7 +153,7 @@ but never mined into the blockchain. | Parameter | Type | Description | | ------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | | `blockNumber` | `*big.Int` (optional) | Selects the block height at which the call runs. It can be `nil`, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available. | ```go @@ -201,7 +202,7 @@ block height. | Parameter | Type | Description | | ----------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | | `blockHash` | `common.Hash` | Block hash. | ```go @@ -218,7 +219,7 @@ pending state. | Parameter | Type | Description | | --------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | ```go PendingCallContractL2(ctx context.Context, msg zkTypes.CallMsg) ([]byte, error) @@ -235,7 +236,7 @@ transactions may be added or removed by miners, but it should provide a basis fo | Parameter | Type | Description | | --------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | ```go EstimateGasL2(ctx context.Context, msg zkTypes.CallMsg) (uint64, error) @@ -1069,7 +1070,7 @@ Returns the fee for the transaction. | Parameter | Type | Description | | --------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | ```go EstimateFee(ctx context.Context, tx zkTypes.CallMsg) (*zkTypes.Fee, error) @@ -1102,7 +1103,7 @@ Estimates the amount of gas required to submit a transaction from L1 to L2. | Parameter | Type | Description | | --------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | ```go EstimateGasL1(ctx context.Context, tx zkTypes.CallMsg) (uint64, error) @@ -1137,7 +1138,7 @@ Estimates the amount of gas required for a transfer transaction. | Parameter | Type | Description | | --------- | -------------------------------------------------- | -------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`TransferCallMsg`](/sdk/go/types/accounts#transfercallmsg) | Contains parameters for transfer call. | +| `msg` | [`TransferCallMsg`](/sdk/go/api/accounts/types#transfercallmsg) | Contains parameters for transfer call. | ```go EstimateGasTransfer(ctx context.Context, msg TransferCallMsg) (uint64, error) @@ -1167,7 +1168,7 @@ Estimates the amount of gas required for a withdrawal transaction. | Parameter | Type | Description | | --------- | ------------------------------------------------------ | ---------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`WithdrawalCallMsg`](/sdk/go/types/accounts#withdrawalcallmsg) | Contains parameters for withdrawal call. | +| `msg` | [`WithdrawalCallMsg`](/sdk/go/api/accounts/types#withdrawalcallmsg) | Contains parameters for withdrawal call. | ```go EstimateGasWithdraw(ctx context.Context, msg WithdrawalCallMsg) (uint64, error) @@ -1197,7 +1198,7 @@ Estimates the amount of gas required for an L1 to L2 execute operation. | Parameter | Type | Description | | --------- | ------------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/types/accounts#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/accounts/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | ```go EstimateL1ToL2Execute(ctx context.Context, msg zkTypes.CallMsg) (uint64, error) diff --git a/content/sdk/20.go/02.api/01.accounts/02.basedeployer.md b/content/sdk/20.go/02.api/01.accounts/02.basedeployer.md index 90bae551..aba81f20 100644 --- a/content/sdk/20.go/02.api/01.accounts/02.basedeployer.md +++ b/content/sdk/20.go/02.api/01.accounts/02.basedeployer.md @@ -24,8 +24,8 @@ Deploys smart contract using CREATE2 method. | Parameter | Type | Description | | --------- | --------------------------------------------------------- | ------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`Create2Transaction`](/sdk/go/types/accounts#create2transaction) | CREATE2 transaction parameters. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`Create2Transaction`](/sdk/go/api/accounts/types#create2transaction) | CREATE2 transaction parameters. | ```go Deploy(auth *TransactOpts, tx Create2Transaction) (common.Hash, error) @@ -55,8 +55,8 @@ Deploys smart contract using CREATE method. | Parameter | Type | Description | | --------- | ------------------------------------------------------- | ------------------------------ | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`CreateTransaction`](/sdk/go/types/accounts#createtransaction) | CREATE transaction parameters. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`CreateTransaction`](/sdk/go/api/accounts/types#createtransaction) | CREATE transaction parameters. | ```go DeployWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error) @@ -86,8 +86,8 @@ Deploys smart account using CREATE2 method. | Parameter | Type | Description | | --------- | --------------------------------------------------------- | ------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`Create2Transaction`](/sdk/go/types/accounts#create2transaction) | CREATE2 transaction parameters. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`Create2Transaction`](/sdk/go/api/accounts/types#create2transaction) | CREATE2 transaction parameters. | ```go DeployAccount(auth *TransactOpts, tx Create2Transaction) (common.Hash, error) @@ -130,8 +130,8 @@ Deploys smart account using CREATE method. | Parameter | Type | Description | | --------- | ------------------------------------------------------- | ------------------------------ | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`CreateTransaction`](/sdk/go/types/accounts#createtransaction) | CREATE transaction parameters. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`CreateTransaction`](/sdk/go/api/accounts/types#createtransaction) | CREATE transaction parameters. | ```go DeployAccountWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error) diff --git a/content/sdk/20.go/02.api/01.accounts/03.wallet.md b/content/sdk/20.go/02.api/01.accounts/03.wallet.md index f62fc895..6cc04be0 100644 --- a/content/sdk/20.go/02.api/01.accounts/03.wallet.md +++ b/content/sdk/20.go/02.api/01.accounts/03.wallet.md @@ -93,7 +93,7 @@ Returns a new instance of `Wallet` with the provided client for the L2 network. | Parameter | Type | Description | | --------- | ---------------------------- | ----------- | -| `client` | [`*clients.Client`](/sdk/go/clients) | L2 client. | +| `client` | [`*clients.Client`](/sdk/go/api/clients/introduction) | L2 client. | ```go Connect(client *clients.Client) (*Wallet, error) diff --git a/content/sdk/20.go/02.api/01.accounts/04.walletl1.md b/content/sdk/20.go/02.api/01.accounts/04.walletl1.md index 177f3487..d2479163 100644 --- a/content/sdk/20.go/02.api/01.accounts/04.walletl1.md +++ b/content/sdk/20.go/02.api/01.accounts/04.walletl1.md @@ -124,7 +124,7 @@ Returns the address of the base token on L1. | Parameter | Type | Description | |-----------|----------------------------------------------------------| ----------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | ```go BaseToken(opts *CallOpts) (common.Address, error) @@ -172,7 +172,7 @@ Returns the balance of the specified token on L1 that can be either ETH or any E | Parameter | Type | Description | | --------- | ------------------------------------------------ | -------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | | `token` | `common.Address` | Token address. | ```go @@ -197,7 +197,7 @@ Returns the amount of approved tokens for a specific L1 bridge. | Parameter | Type | Description | | --------------- | ------------------------------------------------ | --------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | | `token` | `common.Address` | Token address. | | `bridgeAddress` | `common.Address` | Bridge address. | @@ -289,7 +289,7 @@ Returns base cost for L2 transaction. | Parameter | Type | Description | | ------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | | `gasLimit` | `*big.Int` | The gasLimit for the the L2 contract call. | | `gasPerPubdataByte` | `*big.Int` | The L2 gas price for each published L1 calldata byte. | | `gasPrice` | `*big.Int` (optional) | The L1 gas price of the L1 transaction that will send the request for an execute call. | @@ -323,8 +323,8 @@ allowance is calculated solely based on the specified amount. | Parameter | Type | Description | |---------------------| ---------------------------------------- | -------------------------------------------------------------------------------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | -| `msg` | [`DepositCallMsg`](/sdk/go/types/accounts#depositcallmsg) | Deposit call parameters. | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | +| `msg` | [`DepositCallMsg`](/sdk/go/api/accounts/types#depositcallmsg) | Deposit call parameters. | ```go DepositAllowanceParams(opts *CallOpts, msg DepositCallMsg) ([]struct { @@ -490,8 +490,8 @@ skipped. To check the amount of approved tokens for a specific bridge, use the [ | Parameter | Type | Description | | --------- | --------------------------------------------------------- |--------------------------------| -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`DepositTransaction`](/sdk/go/types/accounts#deposittransaction) | Deposit transaction parameters.| +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`DepositTransaction`](/sdk/go/api/accounts/types#deposittransaction) | Deposit transaction parameters.| ```go Deposit(auth *TransactOpts, tx DepositTransaction) (*types.Transaction, error) @@ -664,7 +664,7 @@ included in the estimation. | Parameter | Type | Description | | --------- | ------------------------------------------------- | ------------------------ | | `ctx` | `context.Context` | Context. | -| `msg` | [`DepositCallMsg`](/sdk/go/types/accounts#depositcallmsg) | Deposit call parameters. | +| `msg` | [`DepositCallMsg`](/sdk/go/api/accounts/types#depositcallmsg) | Deposit call parameters. | ```go EstimateGasDeposit(ctx context.Context, msg DepositCallMsg) (uint64, error) @@ -693,7 +693,7 @@ Retrieves the full needed ETH fee for the deposit on both L1 and L2 networks. | Parameter | Type | Description | | --------- | ------------------------------------------------- | ------------------------ | | `ctx` | `context.Context` | Context. | -| `msg` | [`DepositCallMsg`](/sdk/go/types/accounts#depositcallmsg) | Deposit call parameters. | +| `msg` | [`DepositCallMsg`](/sdk/go/api/accounts/types#depositcallmsg) | Deposit call parameters. | ```go FullRequiredDepositFee(ctx context.Context, msg DepositCallMsg) (*FullDepositFee, error) @@ -721,7 +721,7 @@ Proves the inclusion of the L2 -> L1 withdrawal message. | Parameter | Type | Description | | ---------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | | `withdrawalHash` | `common.Hash` | Hash of the L2 transaction where the withdrawal was initiated. | | `index` | `int` | In case there were multiple withdrawals in one transaction, you may pass an index of the withdrawal you want to finalize. | @@ -748,7 +748,7 @@ Checks if the withdrawal finalized on L1 network. | Parameter | Type | Description | | ---------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | | `withdrawalHash` | `common.Hash` | Hash of the L2 transaction where the withdrawal was initiated. | | `index` | `int` | In case there where multiple withdrawals in one transaction, you may pass an index of the withdrawal you want to finalize. | @@ -777,7 +777,7 @@ L1 tokens back to the depositor, otherwise throws the error. | Parameter | Type | Description | | ------------- | --------------------------------------------------------- | ---------------------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | | `depositHash` | `common.Hash` | The L2 transaction hash of the failed deposit. | ```go @@ -803,8 +803,8 @@ Request execution of L2 transaction from L1. | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------- | --------------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`RequestExecuteTransaction`](/sdk/go/types/accounts#requestexecutetransaction) | Request execute transaction parameters. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`RequestExecuteTransaction`](/sdk/go/api/accounts/types#requestexecutetransaction) | Request execute transaction parameters. | ```go RequestExecute(auth *TransactOpts, tx RequestExecuteTransaction) (*types.Transaction, error) @@ -836,7 +836,7 @@ Estimates the amount of gas required for a request execute transaction. | Parameter | Type | Description | | --------- | --------------------------------------------------------------- | -------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`RequestExecuteCallMsg`](/sdk/go/types/accounts#requestexecutecallmsg) | Request execute call parameters. | +| `msg` | [`RequestExecuteCallMsg`](/sdk/go/api/accounts/types#requestexecutecallmsg) | Request execute call parameters. | ```go EstimateGasRequestExecute(ctx context.Context, msg RequestExecuteCallMsg) (uint64, error) @@ -868,8 +868,8 @@ Existing allowance for the bridge is not checked; allowance is calculated solely | Parameter | Type | Description | | --------- | --------------------------------------------------------------- | -------------------------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | -| `msg` | [`RequestExecuteCallMsg`](/sdk/go/types/accounts#requestexecutecallmsg) | Request execute call parameters. | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | +| `msg` | [`RequestExecuteCallMsg`](/sdk/go/api/accounts/types#requestexecutecallmsg) | Request execute call parameters. | ```go RequestExecuteAllowanceParams(opts *CallOpts, msg RequestExecuteCallMsg) (AllowanceParams, error) diff --git a/content/sdk/20.go/02.api/01.accounts/05.walletl2.md b/content/sdk/20.go/02.api/01.accounts/05.walletl2.md index 2c721bef..3968ceeb 100644 --- a/content/sdk/20.go/02.api/01.accounts/05.walletl2.md +++ b/content/sdk/20.go/02.api/01.accounts/05.walletl2.md @@ -153,7 +153,7 @@ Returns the deployment nonce of the account. | Parameter | Type | Description | | --------- | ------------------------------------------------ | ------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | ```go func (a *WalletL2) DeploymentNonce(opts *CallOpts) (*big.Int, error) @@ -205,8 +205,8 @@ to the target account on L1 network. | Parameter | Type | Description | | --------- | --------------------------------------------------------------- | ---------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`WithdrawalTransaction`](/sdk/go/types/accounts#withdrawaltransaction) | Withdrawal transaction parameters. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`WithdrawalTransaction`](/sdk/go/api/accounts/types#withdrawaltransaction) | Withdrawal transaction parameters. | ```go Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (*types.Transaction, error) @@ -235,7 +235,7 @@ Estimates the amount of gas required for a withdrawal transaction. | Parameter | Type | Description | | --------- | ------------------------------------------------------- | --------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`WithdrawalCallMsg`](/sdk/go/types/accounts#withdrawalcallmsg) | Withdrawal call parameters. | +| `msg` | [`WithdrawalCallMsg`](/sdk/go/api/accounts/types#withdrawalcallmsg) | Withdrawal call parameters. | ```go EstimateGasWithdraw(ctx context.Context, msg WithdrawalCallMsg) (uint64, error) @@ -263,8 +263,8 @@ Moves the ETH or any ERC20 token from the associated account to the target accou | Parameter | Type | Description | | --------- | ----------------------------------------------------------- | -------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`TransferTransaction`](/sdk/go/types/accounts#transfertransaction) | Transfer transaction parameters. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`TransferTransaction`](/sdk/go/api/accounts/types#transfertransaction) | Transfer transaction parameters. | ```go Transfer(auth *TransactOpts, tx TransferTransaction) (*types.Transaction, error) @@ -293,7 +293,7 @@ Estimates the amount of gas required for a transfer transaction. | Parameter | Type | Description | | --------- | --------------------------------------------------- | ------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`TransferCallMsg`](/sdk/go/types/accounts#transfercallmsg) | Transfer call parameters. | +| `msg` | [`TransferCallMsg`](/sdk/go/api/accounts/types#transfercallmsg) | Transfer call parameters. | ```go EstimateGasTransfer(ctx context.Context, msg TransferCallMsg) (uint64, error) @@ -323,7 +323,7 @@ into the blockchain. | Parameter | Type | Description | | ------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`CallMsg`](/sdk/go/types/accounts#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`CallMsg`](/sdk/go/api/accounts/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | | `blockNumber` | `*big.Int` (optional) | Selects the block height at which the call runs. It can be `nil`, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available. | ```go @@ -365,7 +365,7 @@ fmt.Println("Symbol: ", symbol) ### PopulateTransaction Designed for users who prefer a simplified approach by providing only the necessary data to create a valid -[EIP-712 transaction](/sdk/go/types/types#transaction712). The only required fields are `Transaction.To` and either +[EIP-712 transaction](/sdk/go/api/types/types#transaction712). The only required fields are `Transaction.To` and either `Transaction.Data` or `Transaction.Value` (or both, if the method is payable). Any other fields that are not set will be prepared by this method. @@ -374,7 +374,7 @@ Any other fields that are not set will be prepared by this method. | Parameter | Type | Description | | --------- | ------------------------------------------- | ----------------------- | | `ctx` | `context.Context` | Context. | -| `tx` | [`Transaction`](/sdk/go/types/accounts#transaction) | Transaction parameters. | +| `tx` | [`Transaction`](/sdk/go/api/accounts/types#transaction) | Transaction parameters. | ```go PopulateTransaction(ctx context.Context, tx Transaction) (*zkTypes.Transaction712, error) @@ -417,7 +417,7 @@ transaction with all fields having appropriate values. To obtain a valid transac | Parameter | Type | Description | | --------- |----------------------------------------------------------------| ------------------------------- | -| `tx` | [`zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | EIP-712 transaction parameters. | +| `tx` | [`zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | EIP-712 transaction parameters. | ```go SignTransaction(tx *zkTypes.Transaction712) ([]byte, error) @@ -465,7 +465,7 @@ Injects a transaction into the pending pool for execution. Any unset transaction | Parameter | Type | Description | | --------- | ------------------------------------------- | ----------------------- | | `ctx` | `context.Context` | Context. | -| `tx` | [`Transaction`](/sdk/go/types/accounts#transaction) | Transaction parameters. | +| `tx` | [`Transaction`](/sdk/go/api/accounts/types#transaction) | Transaction parameters. | ```go SendTransaction(ctx context.Context, tx *Transaction) (common.Hash, error) diff --git a/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md b/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md index a417c0ca..ff17f459 100644 --- a/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md +++ b/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md @@ -21,9 +21,9 @@ requires private key in hex format to be provided. |-----------|--------------------------------------------------------------------|---------------------------------------------------------| | `address` | `common.Address` | Account address. | | `secret` | `interface{}` | Secret used for signing. | -| `signer` | [`*PayloadSigner`](/sdk/go/types/accounts#payloadsigner) | Function used for signing payload. | -| `builder` | [`*TransactionBuilder`](/sdk/go/types/accounts#transactionbuilder) | Function used for populating transaction. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client to connect to. Can be `nil` for offline usage. | +| `signer` | [`*PayloadSigner`](/sdk/go/api/accounts/types#payloadsigner) | Function used for signing payload. | +| `builder` | [`*TransactionBuilder`](/sdk/go/api/accounts/types#transactionbuilder) | Function used for populating transaction. | +| `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | The client to connect to. Can be `nil` for offline usage. | ```go diff --git a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md index 462f6404..de68baaa 100644 --- a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md +++ b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md @@ -10,7 +10,7 @@ Creates a `SmartAccount` instance that uses single ECDSA key for signing payload |--------------|-----------------------------------------------------|----------------------------------------------------------| | `address` | `common.Address` | Account address. | | `privateKey` | `string` | The ECDSA private key. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client to connect to. Can be `nil` for offline usage. | +| `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | The client to connect to. Can be `nil` for offline usage. | ```go diff --git a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md index ec5556c6..22d57b7f 100644 --- a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md +++ b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md @@ -11,7 +11,7 @@ The signature is generated by concatenating signatures created by signing with e |---------------|-----------------------------------------------------|-----------------------------------------------------------| | `address` | `common.Address` | Account address. | | `privateKeys` | `[]string` | The list of the ECDSA private keys. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client to connect to. Can be `nil` for offline usage. | +| `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | The client to connect to. Can be `nil` for offline usage. | ```go NewMultisigECDSASmartAccount(address common.Address, privateKeys []string, client *clients.BaseClient) *SmartAccount @@ -43,7 +43,7 @@ detached from any provider if `nil` is provided. | Parameter | Type | Description | | --------- |---------------------------------------------------|---------------------------------------------------------------------------------------------------------------| -| `client` | [`*clients.DialBase`](/sdk/go/clients#baseclient) | The client to connect the `SmartAccount` to. If `nil`, the `SmartAccount` will be detached from any provider. | +| `client` | [`*clients.DialBase`](/sdk/go/api/clients/baseclient) | The client to connect the `SmartAccount` to. If `nil`, the `SmartAccount` will be detached from any provider. | ```go Connect(client *clients.BaseClient) *SmartAccount @@ -164,7 +164,7 @@ Returns the deployment nonce of the account. | Parameter | Type | Description | | --------- | ------------------------------------------------ | ------------- | -| `opts` | [`CallOpts`](/sdk/go/types/accounts#callopts) (optional) | Call options. | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | ```go DeploymentNonce(opts *CallOpts) (*big.Int, error) @@ -181,7 +181,7 @@ if err != nil { ### `PopulateTransaction` -Populates the transaction `tx` using the provided [`TransactionBuilder`](/sdk/go/types/accounts#transactionbuilder) function. +Populates the transaction `tx` using the provided [`TransactionBuilder`](/sdk/go/api/accounts/types#transactionbuilder) function. If `tx.From` is not set, it sets the value from the `Address()` method which can be utilized in the `TransactionBuilder` function. @@ -190,7 +190,7 @@ be utilized in the `TransactionBuilder` function. | Parameter | Type | Description | |-----------|----------------------------------------------------------|------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be populated. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be populated. | ```go PopulateTransaction(ctx context.Context, tx *zkTypes.Transaction712) error @@ -222,7 +222,7 @@ necessary properties for the transaction to be valid have been populated. | Parameter | Type | Description | |-----------|---------------------------------------------------------|------------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be signed. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be signed. | ```go @@ -252,7 +252,7 @@ The `SignTransaction` is called first to ensure transaction is properly signed. | Parameter | Type | Description | |-----------|---------------------------------------------------------|------------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be signed. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be signed. | ```go SendTransaction(ctx context.Context, tx *zkTypes.Transaction712) (common.Hash, error) @@ -273,7 +273,7 @@ if err != nil { ### `SignMessage` -Signs a message using the provided [`PayloadSigner`](/sdk/go/types/accounts#payloadsigner) function. +Signs a message using the provided [`PayloadSigner`](/sdk/go/api/accounts/types#payloadsigner) function. #### Inputs @@ -297,7 +297,7 @@ if err != nil { ### `SignTypedData` -signs a typed data using the provided [`PayloadSigner`](/sdk/go/types/accounts#payloadsigner) function. +signs a typed data using the provided [`PayloadSigner`](/sdk/go/api/accounts/types#payloadsigner) function. #### Inputs @@ -350,8 +350,8 @@ to the target account on L1 network. | Parameter | Type | Description | | --------- | --------------------------------------------------------------- | ---------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`WithdrawalTransaction`](/sdk/go/types/accounts#withdrawaltransaction) | Withdrawal transaction parameters. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`WithdrawalTransaction`](/sdk/go/api/accounts/types#withdrawaltransaction) | Withdrawal transaction parameters. | ```go Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (common.Hash, error) @@ -406,8 +406,8 @@ Moves the ETH or any ERC20 token from the associated account to the target accou | Parameter | Type | Description | | --------- | ----------------------------------------------------------- | -------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/types/accounts#transactopts) (optional) | Transaction options. | -| `tx` | [`TransferTransaction`](/sdk/go/types/accounts#transfertransaction) | Transfer transaction parameters. | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`TransferTransaction`](/sdk/go/api/accounts/types#transfertransaction) | Transfer transaction parameters. | ```go Transfer(auth *TransactOpts, tx TransferTransaction) (common.Hash, error) diff --git a/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md b/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md index 2b2727da..c5d2ad60 100644 --- a/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md +++ b/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md @@ -12,7 +12,7 @@ the ZKsync Era. ### `SignPayloadWithECDSA` -Implementation of [`PayloadSigner`](/sdk/go/types/accounts#payloadsigner) which signs the payload using +Implementation of [`PayloadSigner`](/sdk/go/api/accounts/types#payloadsigner) which signs the payload using an ECDSA private key. #### Inputs @@ -22,7 +22,7 @@ an ECDSA private key. | `ctx` | `context.Context` | Context. | | `payload` | `[]byte` | The payload that needs to be signed. | | `secret` | `string` | The ECDSA private key. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | Not used and should be `nil`. | +| `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | Not used and should be `nil`. | ```go var SignPayloadWithECDSA PayloadSigner = func(ctx context.Context, payload []byte, secret interface{}, client *clients.BaseClient) ([]byte, error) @@ -146,7 +146,7 @@ if err != nil { ### `SignPayloadWithMultipleECDSA` -Implementation of [`PayloadSigner`](/sdk/go/types/accounts#payloadsigner) which signs the payload using +Implementation of [`PayloadSigner`](/sdk/go/api/accounts/types#payloadsigner) which signs the payload using multiple ECDSA private keys. The signature is generated by concatenating signatures created by signing with each key individually. The length of the resulting signature is `len(secret) * 65`. @@ -158,7 +158,7 @@ The length of the resulting signature is `len(secret) * 65`. | `ctx` | `context.Context` | Context. | | `payload` | `[]byte` | The payload that needs to be signed. | | `secret` | `[]string` | The list of the ECDSA private keys. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | Not used and should be `nil`. | +| `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | Not used and should be `nil`. | ```go var SignPayloadWithMultipleECDSA PayloadSigner = func(ctx context.Context, payload []byte, secret interface{}, client *clients.BaseClient) ([]byte, error) @@ -305,9 +305,9 @@ Expects the secret to be ECDSA private in hex format. | Parameter | Type | Description | |-----------|-----------------------------------------------------------------|------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be populated. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be populated. | | `secret` | `string` | The ECDSA private key. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client which fetches data from the network. | +| `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | The client which fetches data from the network. | ```go var PopulateTransactionECDSA TransactionBuilder = func(ctx context.Context, tx *zkTypes.Transaction712, secret interface{}, client *clients.BaseClient) error @@ -347,9 +347,9 @@ Expects the secret to be a slice of ECDSA private in hex format. | Parameter | Type | Description | |-----------|-----------------------------------------------------------------|-------------------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/types/types#transaction712) | The transaction that needs to be populated. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be populated. | | `secret` | `[]string` | The list of the ECDSA private keys. | -| `client` | [`*clients.BaseClient`](/sdk/go/clients#baseclient) | The client which fetches data from the network. | +| `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | The client which fetches data from the network. | ```go var PopulateTransactionMultipleECDSA TransactionBuilder = func(ctx context.Context, tx *zkTypes.Transaction712, secret interface{}, client *clients.BaseClient) error diff --git a/content/sdk/20.go/02.api/01.accounts/09.types.md b/content/sdk/20.go/02.api/01.accounts/09.types.md index df1768b3..a9673327 100644 --- a/content/sdk/20.go/02.api/01.accounts/09.types.md +++ b/content/sdk/20.go/02.api/01.accounts/09.types.md @@ -225,7 +225,7 @@ func (t *TransactOpts) ToTransactOpts(from common.Address, signer bind.SignerFn) ### `Transaction` -Transaction is similar to [`types.Transaction712`](/sdk/go/types/types#eip712txtype) but does not include the From field. +Transaction is similar to [`types.Transaction712`](/sdk/go/api/types/types#eip712txtype) but does not include the From field. This design is intended for use abstraction which already have an associated account with `AdapterL2`. The From field is bound to the specific account, and thus, it is not included in this type. diff --git a/content/sdk/20.go/02.api/03.contracts/00.contracts.md b/content/sdk/20.go/02.api/03.contracts/00.contracts.md index 9a0e8338..a1e3853f 100644 --- a/content/sdk/20.go/02.api/03.contracts/00.contracts.md +++ b/content/sdk/20.go/02.api/03.contracts/00.contracts.md @@ -10,8 +10,8 @@ an EIP-712 transaction, the deployment function generated with the `abigen` tool the `Deploy` interface is created, which provides methods for the deployment of smart contracts and smart accounts. There are the following objects that implement the `Deploy` interface: -- [`BaseDeployer`](/sdk/go/accounts#basedeployer), -- [`Wallet`](/sdk/go/accounts#wallet). +- [`BaseDeployer`](/sdk/go/api/accounts/basedeployer), +- [`Wallet`](/sdk/go/api/accounts/wallet). Contract instantiation is the same as in the [`geth`](https://geth.ethereum.org/docs/developers/dapp-developer/native-bindings) diff --git a/content/sdk/20.go/02.api/04.utilities/00.utils.md b/content/sdk/20.go/02.api/04.utilities/00.utils.md index b0404c37..7a1cd22e 100644 --- a/content/sdk/20.go/02.api/04.utilities/00.utils.md +++ b/content/sdk/20.go/02.api/04.utilities/00.utils.md @@ -209,7 +209,7 @@ Returns the encoded constructor data for CREATE method used for smart account de | ---------- | -------------------------------------------------------------------------- | ---------------------------------- | | `bytecode` | `[]byte` | Output from zkSolc. | | `calldata` | `[]byte` | ABI encoded constructor arguments. | -| `version` | [`types.AccountAbstractionVersion`](/sdk/go/types/types#accountabstractionversion) | Account abstraction version. | +| `version` | [`types.AccountAbstractionVersion`](/sdk/go/api/types/types#accountabstractionversion) | Account abstraction version. | ```go EncodeCreate2Account(bytecode, calldata, version types.AccountAbstractionVersion) ([]byte, error) @@ -226,7 +226,7 @@ Returns the encoded constructor data for CREATE2 method used for smart account d | `bytecode` | `[]byte` | Output from zkSolc. | | `calldata` | `[]byte` | ABI encoded constructor arguments. | | `salt` | `[]byte` | Randomization element. | -| `version` | [`types.AccountAbstractionVersion`](/sdk/go/types/types#accountabstractionversion) | Account abstraction version. | +| `version` | [`types.AccountAbstractionVersion`](/sdk/go/api/types/types#accountabstractionversion) | Account abstraction version. | ```go EncodeCreate2Account(bytecode, calldata, salt []byte, version types.AccountAbstractionVersion) ([]byte, error) diff --git a/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md b/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md index b4160172..46a5348e 100644 --- a/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md +++ b/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md @@ -71,5 +71,5 @@ Returns a correctly-formed `paymasterParams` object for common paymaster flows. func GetPaymasterParams(paymasterAddress common.Address, paymasterInput types.PaymasterInput) (*types.PaymasterParams, error) ``` -Find out more about the [`PaymasterInput` type](/sdk/go/types/types). +Find out more about the [`PaymasterInput` type](/sdk/go/api/types/types). Check out the [example](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/18_use_paymaster.go) how to use paymaster. diff --git a/content/sdk/20.go/02.api/05.types/00.intro.md b/content/sdk/20.go/02.api/05.types/00.intro.md index 0666e209..79770cc2 100644 --- a/content/sdk/20.go/02.api/05.types/00.intro.md +++ b/content/sdk/20.go/02.api/05.types/00.intro.md @@ -1,14 +1,15 @@ --- -title: Types -description: +title: Introduction +description: Overview of the different type packages +tags: ["go", "sdk", "types", "zksync"] --- Types are placed in three packages for different purposes: -- [`types`](/sdk/go/types/types): Contains common and general types used to build basic features and other types. -- [`eip712`](/sdk/go/types/eip712): Contains types used for EIP-712 implementation. -- [`clients`](/sdk/go/types/clients): Contains types that are meant to be used along with [`Client`](/sdk/go/clients). -- [`accounts`](/sdk/go/types/accounts): Contains types that are meant to be used along with an account, - specifically with the [`Adapter`](/sdk/go/types/accounts) abstraction. - Many types are similar to those from the `geth` library, but the `From` or `Signer` fields are omitted - because these fields are inherited from `Adapter`, which already has an associated account. +- [`types`](/sdk/go/api/types/types): Contains common and general types used to build basic features and other types. +- [`eip712`](/sdk/go/api/eip712/eip712): Contains types used for EIP-712 implementation. +- [`clients`](/sdk/go/api/clients/types): Contains types that are meant to be used along with [`Client`](/sdk/go/api/clients/introduction). +- [`accounts`](/sdk/go/api/accounts/types): Contains types that are meant to be used along with an account, specifically +with the [`Adapter`](/sdk/go/api/accounts/types) abstraction. Many types are similar to those from the `geth` library, but +the `From` or `Signer` fields are omitted because these fields are inherited from `Adapter`, which already has an +associated account. diff --git a/content/sdk/20.go/02.api/05.types/04.types.md b/content/sdk/20.go/02.api/05.types/04.types.md index 75ed6685..b35f4b4b 100644 --- a/content/sdk/20.go/02.api/05.types/04.types.md +++ b/content/sdk/20.go/02.api/05.types/04.types.md @@ -1,8 +1,13 @@ --- -title: Types Package -description: +title: Types +description: Defines various types for ZKsync Go SDK. +tags: ["go", "zksync", "sdk", "types"] --- +This section provides a list of various types used in the ZKsync Go SDK. These types are categorized based on their +purposes and usage within the SDK. The types are crucial for building features, interacting with contracts, managing +transactions, and handling blockchain data in a ZKsync Era environment. + ### `AccountAbstractionVersion` Represents an enumeration of account abstraction versions. From 4d5586ca3e3d73203c4556eff9a83cd875f2a112 Mon Sep 17 00:00:00 2001 From: Ngozi-Txfusion Date: Sat, 6 Jul 2024 18:16:40 +0100 Subject: [PATCH 3/9] fix: update links --- content/sdk/20.go/01.guides/00.getting-started.md | 2 +- content/sdk/20.go/01.guides/01.features.md | 2 +- content/sdk/20.go/01.guides/02.accounts-l1-l2.md | 15 ++++++++------- .../20.go/02.api/01.accounts/06.smartaccount.md | 5 +++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/content/sdk/20.go/01.guides/00.getting-started.md b/content/sdk/20.go/01.guides/00.getting-started.md index 684a4d99..611121b6 100644 --- a/content/sdk/20.go/01.guides/00.getting-started.md +++ b/content/sdk/20.go/01.guides/00.getting-started.md @@ -100,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. diff --git a/content/sdk/20.go/01.guides/01.features.md b/content/sdk/20.go/01.guides/01.features.md index 55765965..c919509d 100644 --- a/content/sdk/20.go/01.guides/01.features.md +++ b/content/sdk/20.go/01.guides/01.features.md @@ -38,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 diff --git a/content/sdk/20.go/01.guides/02.accounts-l1-l2.md b/content/sdk/20.go/01.guides/02.accounts-l1-l2.md index 2f179cdc..2bd753ae 100644 --- a/content/sdk/20.go/01.guides/02.accounts-l1-l2.md +++ b/content/sdk/20.go/01.guides/02.accounts-l1-l2.md @@ -4,7 +4,8 @@ description: Methods for handling transactions between L1 and L2 networks on ZKs 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 +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). @@ -15,7 +16,7 @@ Full examples of actions below are available on the [getting started](/sdk/go/gu ## 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: @@ -25,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: diff --git a/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md b/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md index ff17f459..85e2cb80 100644 --- a/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md +++ b/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md @@ -11,8 +11,9 @@ and custom signing method used for signing messages, typed data, and transaction ### `Init` -Creates a new `SmartAccount` instance. By default, it uses [`SignPayloadWithECDSA`](/sdk/go/smart-account-utils#signpayloadwithecdsa) -as a signer and [`PopulateTransactionECDSA`](/sdk/go/smart-account-utils#populatetransactionecdsa) as a builder and +Creates a new `SmartAccount` instance. By default, it uses [`SignPayloadWithECDSA`](/sdk/go/api/accounts/smart-account-utils#signpayloadwithecdsa) +as a signer and [`PopulateTransactionECDSA`](/sdk/go/api/accounts/smart-account-utils#populatetransactionecdsa) as +a builder and requires private key in hex format to be provided. #### Inputs From 4219003ea5a916fe01c3260aea29475e4f5c30f0 Mon Sep 17 00:00:00 2001 From: Ngozi-Txfusion Date: Mon, 8 Jul 2024 09:53:41 +0100 Subject: [PATCH 4/9] fix: update url --- .../sdk/20.go/02.api/05.types/{00.intro.md => 00.introduction.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/sdk/20.go/02.api/05.types/{00.intro.md => 00.introduction.md} (100%) diff --git a/content/sdk/20.go/02.api/05.types/00.intro.md b/content/sdk/20.go/02.api/05.types/00.introduction.md similarity index 100% rename from content/sdk/20.go/02.api/05.types/00.intro.md rename to content/sdk/20.go/02.api/05.types/00.introduction.md From a1cf4e3fc6f5a787f50d577a06cf20c7c0bc2b94 Mon Sep 17 00:00:00 2001 From: Ngozi-Txfusion Date: Mon, 8 Jul 2024 10:54:37 +0100 Subject: [PATCH 5/9] fix: update types --- ...ccount.md => 07.smartaccount-factories.md} | 39 +++++++++++++++++-- .../00.newecdsasmartaccount.md | 34 ---------------- .../{05.types/04.types.md => 05.types.md} | 12 +++++- .../20.go/02.api/05.types/00.introduction.md | 15 ------- 4 files changed, 47 insertions(+), 53 deletions(-) rename content/sdk/20.go/02.api/01.accounts/{07.smartaccount-factories/01.newmultisigecdsasmartaccount.md => 07.smartaccount-factories.md} (90%) delete mode 100644 content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md rename content/sdk/20.go/02.api/{05.types/04.types.md => 05.types.md} (94%) delete mode 100644 content/sdk/20.go/02.api/05.types/00.introduction.md diff --git a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md similarity index 90% rename from content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md rename to content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md index 22d57b7f..c8e5d703 100644 --- a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/01.newmultisigecdsasmartaccount.md +++ b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md @@ -1,9 +1,42 @@ --- -title: NewMultisigECDSASmartAccount -description: -tags: +title: SmartAccount Factories +description: NewECDSASmartAccount and NewMultisigECDSASmartAccount for SmartAccount +tags: ["newecdsa", "newmultisigecdsa", "go" "sdk"] --- +## NewECDSASmartAccount + +Creates a `SmartAccount` instance that uses single ECDSA key for signing payload. + +| Parameter | Type | Description | +|--------------|-----------------------------------------------------|----------------------------------------------------------| +| `address` | `common.Address` | Account address. | +| `privateKey` | `string` | The ECDSA private key. | +| `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | The client to connect to. Can be `nil` for offline usage. | + +```go + +func NewECDSASmartAccount(address common.Address, privateKey string, client *clients.BaseClient) *SmartAccount +``` + +#### Example + +```go +privateKey := os.Getenv("PRIVATE_KEY") +address := common.HexToAddress("") +ZkSyncEraProvider := "https://sepolia.era.zksync.dev" + +client, err := clients.DialBase(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +account := accounts.NewECDSASmartAccount(address, privateKey, client) +``` + +## NewMultisigECDSASmartAccount + Creates a `SmartAccount` instance that uses multiple ECDSA keys for signing payloads. The signature is generated by concatenating signatures created by signing with each key individually. diff --git a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md deleted file mode 100644 index de68baaa..00000000 --- a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories/00.newecdsasmartaccount.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: NewECDSASmartAccount -description: -tags: ---- - -Creates a `SmartAccount` instance that uses single ECDSA key for signing payload. - -| Parameter | Type | Description | -|--------------|-----------------------------------------------------|----------------------------------------------------------| -| `address` | `common.Address` | Account address. | -| `privateKey` | `string` | The ECDSA private key. | -| `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | The client to connect to. Can be `nil` for offline usage. | - -```go - -func NewECDSASmartAccount(address common.Address, privateKey string, client *clients.BaseClient) *SmartAccount -``` - -#### Example - -```go -privateKey := os.Getenv("PRIVATE_KEY") -address := common.HexToAddress("") -ZkSyncEraProvider := "https://sepolia.era.zksync.dev" - -client, err := clients.DialBase(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -account := accounts.NewECDSASmartAccount(address, privateKey, client) -``` diff --git a/content/sdk/20.go/02.api/05.types/04.types.md b/content/sdk/20.go/02.api/05.types.md similarity index 94% rename from content/sdk/20.go/02.api/05.types/04.types.md rename to content/sdk/20.go/02.api/05.types.md index b35f4b4b..ba9d95af 100644 --- a/content/sdk/20.go/02.api/05.types/04.types.md +++ b/content/sdk/20.go/02.api/05.types.md @@ -1,9 +1,19 @@ --- -title: Types +title: Types and Interfaces description: Defines various types for ZKsync Go SDK. tags: ["go", "zksync", "sdk", "types"] --- +Types are placed in three packages for different purposes: + +- [`types`](/sdk/go/api/types/types): Contains common and general types used to build basic features and other types. +- [`eip712`](/sdk/go/api/eip712/eip712): Contains types used for EIP-712 implementation. +- [`clients`](/sdk/go/api/clients/types): Contains types that are meant to be used along with [`Client`](/sdk/go/api/clients/introduction). +- [`accounts`](/sdk/go/api/accounts/types): Contains types that are meant to be used along with an account, specifically +with the [`Adapter`](/sdk/go/api/accounts/types) abstraction. Many types are similar to those from the `geth` library, but +the `From` or `Signer` fields are omitted because these fields are inherited from `Adapter`, which already has an +associated account. + This section provides a list of various types used in the ZKsync Go SDK. These types are categorized based on their purposes and usage within the SDK. The types are crucial for building features, interacting with contracts, managing transactions, and handling blockchain data in a ZKsync Era environment. diff --git a/content/sdk/20.go/02.api/05.types/00.introduction.md b/content/sdk/20.go/02.api/05.types/00.introduction.md deleted file mode 100644 index 79770cc2..00000000 --- a/content/sdk/20.go/02.api/05.types/00.introduction.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: Introduction -description: Overview of the different type packages -tags: ["go", "sdk", "types", "zksync"] ---- - -Types are placed in three packages for different purposes: - -- [`types`](/sdk/go/api/types/types): Contains common and general types used to build basic features and other types. -- [`eip712`](/sdk/go/api/eip712/eip712): Contains types used for EIP-712 implementation. -- [`clients`](/sdk/go/api/clients/types): Contains types that are meant to be used along with [`Client`](/sdk/go/api/clients/introduction). -- [`accounts`](/sdk/go/api/accounts/types): Contains types that are meant to be used along with an account, specifically -with the [`Adapter`](/sdk/go/api/accounts/types) abstraction. Many types are similar to those from the `geth` library, but -the `From` or `Signer` fields are omitted because these fields are inherited from `Adapter`, which already has an -associated account. From 9db2cf038fbbcd078ef49fd77732586c96389f50 Mon Sep 17 00:00:00 2001 From: Ngozi-Txfusion Date: Mon, 8 Jul 2024 11:25:24 +0100 Subject: [PATCH 6/9] fix: updated smartaccount --- .../sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md | 4 ++-- content/sdk/20.go/02.api/05.types.md | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md index c8e5d703..a31d4a08 100644 --- a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md +++ b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md @@ -1,7 +1,7 @@ --- title: SmartAccount Factories -description: NewECDSASmartAccount and NewMultisigECDSASmartAccount for SmartAccount -tags: ["newecdsa", "newmultisigecdsa", "go" "sdk"] +description: NewECDSA and NewMultisigECDSA for SmartAccount +tags: ["ecdsa", "smartaccount", "go", "sdk"] --- ## NewECDSASmartAccount diff --git a/content/sdk/20.go/02.api/05.types.md b/content/sdk/20.go/02.api/05.types.md index ba9d95af..8ee7d787 100644 --- a/content/sdk/20.go/02.api/05.types.md +++ b/content/sdk/20.go/02.api/05.types.md @@ -15,8 +15,7 @@ the `From` or `Signer` fields are omitted because these fields are inherited fro associated account. This section provides a list of various types used in the ZKsync Go SDK. These types are categorized based on their -purposes and usage within the SDK. The types are crucial for building features, interacting with contracts, managing -transactions, and handling blockchain data in a ZKsync Era environment. +purposes and usage within the SDK. ### `AccountAbstractionVersion` From 2290b497af73eb4e713ee4d2c0af7b865d4bcd5b Mon Sep 17 00:00:00 2001 From: Ngozi-Txfusion Date: Mon, 8 Jul 2024 11:30:47 +0100 Subject: [PATCH 7/9] fix: update types --- content/sdk/20.go/01.guides/01.features.md | 10 +++++----- .../20.go/02.api/00.clients/01.baseclient.md | 18 +++++++++--------- .../20.go/02.api/01.accounts/05.walletl2.md | 4 ++-- .../01.accounts/07.smartaccount-factories.md | 6 +++--- .../01.accounts/08.smart-account-utils.md | 4 ++-- .../sdk/20.go/02.api/01.accounts/09.types.md | 2 +- .../sdk/20.go/02.api/04.utilities/00.utils.md | 4 ++-- .../02.api/04.utilities/01.paymaster-utils.md | 2 +- content/sdk/20.go/02.api/05.types.md | 2 +- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/content/sdk/20.go/01.guides/01.features.md b/content/sdk/20.go/01.guides/01.features.md index c919509d..ffee8c41 100644 --- a/content/sdk/20.go/01.guides/01.features.md +++ b/content/sdk/20.go/01.guides/01.features.md @@ -21,14 +21,14 @@ This document will focus solely on how to pass these arguments to the SDK. ## EIP-712 Metadata -[`EIP712Meta`](/sdk/go/api/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/api/types/types#callmsg) -- [`types.Transaction712`](/sdk/go/api/types/types#transaction712) -- [`accounts.CallMsg`](/sdk/go/api/types/types#callmsg) -- [`accounts.Transaction`](/sdk/go/api/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 diff --git a/content/sdk/20.go/02.api/00.clients/01.baseclient.md b/content/sdk/20.go/02.api/00.clients/01.baseclient.md index ef0c204c..2124bccd 100644 --- a/content/sdk/20.go/02.api/00.clients/01.baseclient.md +++ b/content/sdk/20.go/02.api/00.clients/01.baseclient.md @@ -54,7 +54,7 @@ defer wsClient.Close() Executes a log filter operation, blocking during execution, and returns all the results in one batch. This method is a replacement for `FilterLogs` because the returned `types.Log` type does not contain additional data specific to L2, -as found in [`Log`](/sdk/go/api/types/types#log). The `FilterLogs` method is kept in order to be compatible with `bind.ContractBackend`, +as found in [`Log`](/sdk/go/api/types#log). The `FilterLogs` method is kept in order to be compatible with `bind.ContractBackend`, and this method can be used, but additional L2 data won't be retrieved. #### Inputs @@ -96,7 +96,7 @@ for _, l := range zkLogs { Creates a background log filtering operation, returning a subscription immediately, which can be used to stream the found events. This method is a replacement for `SubscribeFilterLogs` because the returned `types.Log` type does not contain additional data specific to L2, as found -in [`Log`](/sdk/go/api/types/types#log). The `SubscribeFilterLogs` method is +in [`Log`](/sdk/go/api/types#log). The `SubscribeFilterLogs` method is kept in order to be compatible with `bind.ContractBackend`, and this method can be used, but additional L2 data won't be retrieved. @@ -106,7 +106,7 @@ won't be retrieved. | --------- | --------------------------------------------------------------------------------------------- | -------------------------- | | `ctx` | `context.Context` | Context. | | `query` | [`ethereum.FilterQuery`](https://pkg.go.dev/github.com/ethereum/go-ethereum@v1.12.0#FilterQuery) | Filter query parameters. | -| `ch` | [`chan<- zkTypes.Log`](/sdk/go/api/types/types#log) | Channel that receives Log. | +| `ch` | [`chan<- zkTypes.Log`](/sdk/go/api/types#log) | Channel that receives Log. | ```go SubscribeFilterLogsL2(ctx context.Context, query ethereum.FilterQuery, ch chan<- zkTypes.Log) (ethereum.Subscription, error) @@ -153,7 +153,7 @@ but never mined into the blockchain. | Parameter | Type | Description | | ------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | | `blockNumber` | `*big.Int` (optional) | Selects the block height at which the call runs. It can be `nil`, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available. | ```go @@ -202,7 +202,7 @@ block height. | Parameter | Type | Description | | ----------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | | `blockHash` | `common.Hash` | Block hash. | ```go @@ -219,7 +219,7 @@ pending state. | Parameter | Type | Description | | --------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | ```go PendingCallContractL2(ctx context.Context, msg zkTypes.CallMsg) ([]byte, error) @@ -236,7 +236,7 @@ transactions may be added or removed by miners, but it should provide a basis fo | Parameter | Type | Description | | --------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | ```go EstimateGasL2(ctx context.Context, msg zkTypes.CallMsg) (uint64, error) @@ -1070,7 +1070,7 @@ Returns the fee for the transaction. | Parameter | Type | Description | | --------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | ```go EstimateFee(ctx context.Context, tx zkTypes.CallMsg) (*zkTypes.Fee, error) @@ -1103,7 +1103,7 @@ Estimates the amount of gas required to submit a transaction from L1 to L2. | Parameter | Type | Description | | --------- | ---------------------------------------- | ---------------------------------------------------------------- | | `ctx` | `context.Context` | Context. | -| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | +| `msg` | [`zkTypes.CallMsg`](/sdk/go/api/types#callmsg) | Contains parameters for contract call using EIP-712 transaction. | ```go EstimateGasL1(ctx context.Context, tx zkTypes.CallMsg) (uint64, error) diff --git a/content/sdk/20.go/02.api/01.accounts/05.walletl2.md b/content/sdk/20.go/02.api/01.accounts/05.walletl2.md index 3968ceeb..ff702eb2 100644 --- a/content/sdk/20.go/02.api/01.accounts/05.walletl2.md +++ b/content/sdk/20.go/02.api/01.accounts/05.walletl2.md @@ -365,7 +365,7 @@ fmt.Println("Symbol: ", symbol) ### PopulateTransaction Designed for users who prefer a simplified approach by providing only the necessary data to create a valid -[EIP-712 transaction](/sdk/go/api/types/types#transaction712). The only required fields are `Transaction.To` and either +[EIP-712 transaction](/sdk/go/api/types#transaction712). The only required fields are `Transaction.To` and either `Transaction.Data` or `Transaction.Value` (or both, if the method is payable). Any other fields that are not set will be prepared by this method. @@ -417,7 +417,7 @@ transaction with all fields having appropriate values. To obtain a valid transac | Parameter | Type | Description | | --------- |----------------------------------------------------------------| ------------------------------- | -| `tx` | [`zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | EIP-712 transaction parameters. | +| `tx` | [`zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | EIP-712 transaction parameters. | ```go SignTransaction(tx *zkTypes.Transaction712) ([]byte, error) diff --git a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md index a31d4a08..7a08e102 100644 --- a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md +++ b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md @@ -223,7 +223,7 @@ be utilized in the `TransactionBuilder` function. | Parameter | Type | Description | |-----------|----------------------------------------------------------|------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be populated. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be populated. | ```go PopulateTransaction(ctx context.Context, tx *zkTypes.Transaction712) error @@ -255,7 +255,7 @@ necessary properties for the transaction to be valid have been populated. | Parameter | Type | Description | |-----------|---------------------------------------------------------|------------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be signed. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be signed. | ```go @@ -285,7 +285,7 @@ The `SignTransaction` is called first to ensure transaction is properly signed. | Parameter | Type | Description | |-----------|---------------------------------------------------------|------------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be signed. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be signed. | ```go SendTransaction(ctx context.Context, tx *zkTypes.Transaction712) (common.Hash, error) diff --git a/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md b/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md index c5d2ad60..4b51a01c 100644 --- a/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md +++ b/content/sdk/20.go/02.api/01.accounts/08.smart-account-utils.md @@ -305,7 +305,7 @@ Expects the secret to be ECDSA private in hex format. | Parameter | Type | Description | |-----------|-----------------------------------------------------------------|------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be populated. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be populated. | | `secret` | `string` | The ECDSA private key. | | `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | The client which fetches data from the network. | @@ -347,7 +347,7 @@ Expects the secret to be a slice of ECDSA private in hex format. | Parameter | Type | Description | |-----------|-----------------------------------------------------------------|-------------------------------------------------| | `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types/types#transaction712) | The transaction that needs to be populated. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be populated. | | `secret` | `[]string` | The list of the ECDSA private keys. | | `client` | [`*clients.BaseClient`](/sdk/go/api/clients/baseclient) | The client which fetches data from the network. | diff --git a/content/sdk/20.go/02.api/01.accounts/09.types.md b/content/sdk/20.go/02.api/01.accounts/09.types.md index a9673327..9ea58ed8 100644 --- a/content/sdk/20.go/02.api/01.accounts/09.types.md +++ b/content/sdk/20.go/02.api/01.accounts/09.types.md @@ -225,7 +225,7 @@ func (t *TransactOpts) ToTransactOpts(from common.Address, signer bind.SignerFn) ### `Transaction` -Transaction is similar to [`types.Transaction712`](/sdk/go/api/types/types#eip712txtype) but does not include the From field. +Transaction is similar to [`types.Transaction712`](/sdk/go/api/types#eip712txtype) but does not include the From field. This design is intended for use abstraction which already have an associated account with `AdapterL2`. The From field is bound to the specific account, and thus, it is not included in this type. diff --git a/content/sdk/20.go/02.api/04.utilities/00.utils.md b/content/sdk/20.go/02.api/04.utilities/00.utils.md index 7a1cd22e..bc240521 100644 --- a/content/sdk/20.go/02.api/04.utilities/00.utils.md +++ b/content/sdk/20.go/02.api/04.utilities/00.utils.md @@ -209,7 +209,7 @@ Returns the encoded constructor data for CREATE method used for smart account de | ---------- | -------------------------------------------------------------------------- | ---------------------------------- | | `bytecode` | `[]byte` | Output from zkSolc. | | `calldata` | `[]byte` | ABI encoded constructor arguments. | -| `version` | [`types.AccountAbstractionVersion`](/sdk/go/api/types/types#accountabstractionversion) | Account abstraction version. | +| `version` | [`types.AccountAbstractionVersion`](/sdk/go/api/types#accountabstractionversion) | Account abstraction version. | ```go EncodeCreate2Account(bytecode, calldata, version types.AccountAbstractionVersion) ([]byte, error) @@ -226,7 +226,7 @@ Returns the encoded constructor data for CREATE2 method used for smart account d | `bytecode` | `[]byte` | Output from zkSolc. | | `calldata` | `[]byte` | ABI encoded constructor arguments. | | `salt` | `[]byte` | Randomization element. | -| `version` | [`types.AccountAbstractionVersion`](/sdk/go/api/types/types#accountabstractionversion) | Account abstraction version. | +| `version` | [`types.AccountAbstractionVersion`](/sdk/go/api/types#accountabstractionversion) | Account abstraction version. | ```go EncodeCreate2Account(bytecode, calldata, salt []byte, version types.AccountAbstractionVersion) ([]byte, error) diff --git a/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md b/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md index 46a5348e..28b678a2 100644 --- a/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md +++ b/content/sdk/20.go/02.api/04.utilities/01.paymaster-utils.md @@ -71,5 +71,5 @@ Returns a correctly-formed `paymasterParams` object for common paymaster flows. func GetPaymasterParams(paymasterAddress common.Address, paymasterInput types.PaymasterInput) (*types.PaymasterParams, error) ``` -Find out more about the [`PaymasterInput` type](/sdk/go/api/types/types). +Find out more about the [`PaymasterInput` type](/sdk/go/api/types). Check out the [example](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/18_use_paymaster.go) how to use paymaster. diff --git a/content/sdk/20.go/02.api/05.types.md b/content/sdk/20.go/02.api/05.types.md index 8ee7d787..9ec0559b 100644 --- a/content/sdk/20.go/02.api/05.types.md +++ b/content/sdk/20.go/02.api/05.types.md @@ -6,7 +6,7 @@ tags: ["go", "zksync", "sdk", "types"] Types are placed in three packages for different purposes: -- [`types`](/sdk/go/api/types/types): Contains common and general types used to build basic features and other types. +- [`types`](/sdk/go/api/types): Contains common and general types used to build basic features and other types. - [`eip712`](/sdk/go/api/eip712/eip712): Contains types used for EIP-712 implementation. - [`clients`](/sdk/go/api/clients/types): Contains types that are meant to be used along with [`Client`](/sdk/go/api/clients/introduction). - [`accounts`](/sdk/go/api/accounts/types): Contains types that are meant to be used along with an account, specifically From 35abc2057dc541b01219179e814190fb1ffb8598 Mon Sep 17 00:00:00 2001 From: Ngozi-Txfusion Date: Mon, 8 Jul 2024 11:44:44 +0100 Subject: [PATCH 8/9] fix: update contracts description --- content/sdk/20.go/02.api/03.contracts/00.contracts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/sdk/20.go/02.api/03.contracts/00.contracts.md b/content/sdk/20.go/02.api/03.contracts/00.contracts.md index a1e3853f..0c86db80 100644 --- a/content/sdk/20.go/02.api/03.contracts/00.contracts.md +++ b/content/sdk/20.go/02.api/03.contracts/00.contracts.md @@ -1,6 +1,6 @@ --- title: Contracts -description: Provides methods and interfaces for deploying smart contracts and smart accounts on ZKsync Era +description: Methods and interfaces for deploying smart contracts on ZKsync Era tags: ["zksync", "contracts", "deployment", "go", "sdk"] --- From 1fea501528fe116ff83438faa425b2a47b9adad1 Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Mon, 8 Jul 2024 13:33:20 +0200 Subject: [PATCH 9/9] chore: fix errors --- .../02.api/01.accounts/06.smartaccount.md | 424 ++++++++++++++++++ .../01.accounts/07.smartaccount-factories.md | 424 ------------------ content/sdk/20.go/02.api/05.types.md | 2 +- 3 files changed, 425 insertions(+), 425 deletions(-) diff --git a/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md b/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md index 85e2cb80..19da7ee3 100644 --- a/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md +++ b/content/sdk/20.go/02.api/01.accounts/06.smartaccount.md @@ -56,3 +56,427 @@ account := accounts.NewSmartAccount( &accounts.PopulateTransactionECDSA, nil) ``` + +### `Connect` + +Creates a new instance of SmartAccount connected to a client or +detached from any provider if `nil` is provided. + +#### Inputs + +| Parameter | Type | Description | +| --------- |---------------------------------------------------|---------------------------------------------------------------------------------------------------------------| +| `client` | [`*clients.DialBase`](/sdk/go/api/clients/baseclient) | The client to connect the `SmartAccount` to. If `nil`, the `SmartAccount` will be detached from any provider. | + +```go +Connect(client *clients.BaseClient) *SmartAccount +``` + +#### Example + +```go +privateKey := os.Getenv("PRIVATE_KEY") +ZkSyncEraProvider := "https://testnet.era.zksync.dev" + +client, err := clients.Dial(ZkSyncEraProvider) +if err != nil { + log.Panic(err) +} +defer client.Close() + +account := accounts.NewECDSASmartAccount(Address1, PrivateKey1, nil) +account = account.Connect(client) +``` + +### `Address` + +Returns the address of the associated account. + +```go +Address() common.Address +``` + +#### Example + +```go +fmt.Println("Address: ", account.Address()) +``` + +### `Balance` + +Returns the balance of the specified token that can be either ETH or any ERC20 token. The block number can be `nil`, +in which case the balance is taken from the latest known block. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------------- | +| `ctx` | `context.Context` | Context. | +| `token` | `common.Address` | L2 token address. | +| `at` | `*big.Int` | Block number. | + +```go +Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error) +``` + +#### Example + +```go +balance, err := account.Balance(context.Background(), utils.EthAddress, nil) +if err != nil { + log.Panic(err) +} +fmt.Println("Balance: ", balance) +``` + +### `AllBalances` + +Returns all balances for confirmed tokens given by an associated account. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +AllBalances(ctx context.Context) (map[common.Address]*big.Int, error) +``` + +#### Example + +```go +balances, err := account.AllBalances(context.Background()) +if err != nil { + log.Panic(err) +} +fmt.Printf("Balances: %+v\n", balances) +``` + +### `Nonce` + +Returns the account nonce of the associated account. The block number can be `nil`, in which case the nonce is taken +from the latest known block. + +#### Inputs + +| Parameter | Type | Description | +| ------------- | --------------------- | ------------- | +| `ctx` | `context.Context` | Context. | +| `blockNumber` | `*big.Int` (optional) | Block number. | + +```go +Nonce(ctx context.Context, blockNumber *big.Int) (uint64, error) +``` + +#### Example + +```go +nonce, err := account.Nonce(context.Background(), big.NewInt(9000)) +if err != nil { + log.Panic(err) +} +fmt.Println("Nonce: ", nonce) +``` + +### `DeploymentNonce` + +Returns the deployment nonce of the account. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ------------------------------------------------ | ------------- | +| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | + +```go +DeploymentNonce(opts *CallOpts) (*big.Int, error) +``` + +#### Example + +```go +deploymentNonce, err := account.DeploymentNonce(nil) +if err != nil { + log.Panic(err) +} +``` + +### `PopulateTransaction` + +Populates the transaction `tx` using the provided [`TransactionBuilder`](/sdk/go/api/accounts/types#transactionbuilder) function. +If `tx.From` is not set, it sets the value from the `Address()` method which can +be utilized in the `TransactionBuilder` function. + +#### Inputs + +| Parameter | Type | Description | +|-----------|----------------------------------------------------------|------------------------------------| +| `ctx` | `context.Context` | Context. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be populated. | + +```go +PopulateTransaction(ctx context.Context, tx *zkTypes.Transaction712) error +``` + +#### Example + +```go +address := common.HexToAddress("") +tx := &zkTypes.Transaction712{ + To: &address, + Value: big.NewInt(7_000_000_000), +} + +err = account.PopulateTransaction(context.Background(), tx) +if err != nil { + log.Panic(err) +} +``` + +### `SignTransaction` + +Returns a signed transaction that is ready to be broadcast to +the network. The `PopulateTransaction` method is called first to ensure that all +necessary properties for the transaction to be valid have been populated. + +#### Inputs + +| Parameter | Type | Description | +|-----------|---------------------------------------------------------|------------------------------------------| +| `ctx` | `context.Context` | Context. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be signed. | + +```go + +SignTransaction(ctx context.Context, tx *zkTypes.Transaction712) ([]byte, error) +``` + +#### Example + +```go +address := common.HexToAddress("") +signedTx, err := account.SignTransaction(context.Background(), &zkTypes.Transaction712{ + To: &address, + Value: big.NewInt(1_000_000_000_000_000_000), // 1ETH +}) +if err != nil { + log.Panic(err) +} +``` + +### `SendTransaction` + +Injects a transaction into the pending pool for execution. +The `SignTransaction` is called first to ensure transaction is properly signed. + +#### Inputs + +| Parameter | Type | Description | +|-----------|---------------------------------------------------------|------------------------------------------| +| `ctx` | `context.Context` | Context. | +| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be signed. | + +```go +SendTransaction(ctx context.Context, tx *zkTypes.Transaction712) (common.Hash, error) +``` + +#### Example + +```go +address := common.HexToAddress("") +txHash, err := account.SendTransaction(context.Background(), &zkTypes.Transaction712{ + To: &address, + Value: big.NewInt(1_000_000_000_000_000_000), // 1ETH +}) +if err != nil { + log.Panic(err) +} +``` + +### `SignMessage` + +Signs a message using the provided [`PayloadSigner`](/sdk/go/api/accounts/types#payloadsigner) function. + +#### Inputs + +| Parameter | Type | Description | +|-----------|-------------------|--------------------------------------| +| `ctx` | `context.Context` | Context. | +| `message` | `[]byte` | The message that needs to be signed. | + +```go +SignMessage(ctx context.Context, message []byte) ([]byte, error) +``` + +#### Example + +```go +signature, err := account.SignMessage(context.Background(), []byte("Hello World!")) +if err != nil { + log.Panic(err) +} +``` + +### `SignTypedData` + +signs a typed data using the provided [`PayloadSigner`](/sdk/go/api/accounts/types#payloadsigner) function. + +#### Inputs + +| Parameter | Type | Description | +|-------------|-----------------------|-----------------------------------------| +| `ctx` | `context.Context` | Context. | +| `typedData` | `apitypes.TypedData` | The typed data that needs to be signed. | + +```go +SignTypedData(ctx context.Context, typedData apitypes.TypedData) ([]byte, error) +``` + +#### Example + +```go +signature, err := account.SignTypedData(context.Background(), apitypes.TypedData{ + Domain: apitypes.TypedDataDomain{ + Name: "Example", + Version: "1", + ChainId: math.NewHexOrDecimal256(270), + }, + Types: apitypes.Types{ + "Person": []apitypes.Type{ + {Name: "name", Type: "string"}, + {Name: "age", Type: "uint8"}, + }, + "EIP712Domain": []apitypes.Type{ + {Name: "name", Type: "string"}, + {Name: "version", Type: "string"}, + {Name: "chainId", Type: "uint256"}, + }, + }, + PrimaryType: "Person", + Message: apitypes.TypedDataMessage{ + "name": "John", + "age": hexutil.EncodeUint64(30), + }, +}) +if err != nil { + log.Panic(err) +} +``` + +### `Withdraw` + +Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network +to the target account on L1 network. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------------- | ---------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`WithdrawalTransaction`](/sdk/go/api/accounts/types#withdrawaltransaction) | Withdrawal transaction parameters. | + +```go +Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (common.Hash, error) +``` + +#### Examples + +Withdraw ETH. + +```go +txHash, err := account.Withdraw(nil, accounts.WithdrawalTransaction{ + To: account.Address(), + Amount: big.NewInt(1_000_000_000_000_000_000), + Token: utils.LegacyEthAddress, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Withdraw transaction: ", txHash) +``` + +Withdraw ETH using paymaster to facilitate fee payment with an ERC20 token. + +```go +token := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F"); // Crown token which can be minted for free +paymaster := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46"); // Paymaster for Crown token + +paymasterParams, err := utils.GetPaymasterParams( + paymaster, + &zkTypes.ApprovalBasedPaymasterInput{ + Token: token, + MinimalAllowance: big.NewInt(1), + InnerInput: []byte{}, +}) +if err != nil { + log.Panic(err) +} + +txHash, err := account.Withdraw(nil, accounts.WithdrawalTransaction{ + To: account.Address(), + Amount: big.NewInt(1_000_000_000_000_000_000), + Token: utils.LegacyEthAddress, + PaymasterParams: paymasterParams, + }) +``` + +### `Transfer` + +Moves the ETH or any ERC20 token from the associated account to the target account. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------------------------------------------------- | -------------------------------- | +| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | +| `tx` | [`TransferTransaction`](/sdk/go/api/accounts/types#transfertransaction) | Transfer transaction parameters. | + +```go +Transfer(auth *TransactOpts, tx TransferTransaction) (common.Hash, error) +``` + +#### Examples + +Transfer ETH. + +```go +txHash, err := account.Transfer(nil, accounts.TransferTransaction{ + To: Address2, + Amount: amount, + Token: utils.LegacyEthAddress, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Transaction: ", txHash) +``` + +Transfer ETH using paymaster to facilitate fee payment with an ERC20 token. + +```go +token := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F"); // Crown token which can be minted for free +paymaster := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46"); // Paymaster for Crown token + +paymasterParams, err := utils.GetPaymasterParams( + paymaster, + &zkTypes.ApprovalBasedPaymasterInput{ + Token: token, + MinimalAllowance: big.NewInt(1), + InnerInput: []byte{}, +}) +if err != nil { + log.Panic(err) +} + +txHash, err := account.Transfer(nil, accounts.TransferTransaction{ + To: Address2, + Amount: amount, + Token: utils.LegacyEthAddress, + PaymasterParams: paymasterParams, +}) +if err != nil { + log.Panic(err) +} +fmt.Println("Transaction: ", txHash) +``` diff --git a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md index 7a08e102..471cd049 100644 --- a/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md +++ b/content/sdk/20.go/02.api/01.accounts/07.smartaccount-factories.md @@ -66,427 +66,3 @@ defer client.Close() account := accounts.NewMultisigECDSASmartAccount(address, []string{privateKey1, privateKey2}, client) ``` - -### `Connect` - -Creates a new instance of SmartAccount connected to a client or -detached from any provider if `nil` is provided. - -#### Inputs - -| Parameter | Type | Description | -| --------- |---------------------------------------------------|---------------------------------------------------------------------------------------------------------------| -| `client` | [`*clients.DialBase`](/sdk/go/api/clients/baseclient) | The client to connect the `SmartAccount` to. If `nil`, the `SmartAccount` will be detached from any provider. | - -```go -Connect(client *clients.BaseClient) *SmartAccount -``` - -#### Example - -```go -privateKey := os.Getenv("PRIVATE_KEY") -ZkSyncEraProvider := "https://testnet.era.zksync.dev" - -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - -account := accounts.NewECDSASmartAccount(Address1, PrivateKey1, nil) -account = account.Connect(client) -``` - -### `Address` - -Returns the address of the associated account. - -```go -Address() common.Address -``` - -#### Example - -```go -fmt.Println("Address: ", account.Address()) -``` - -### `Balance` - -Returns the balance of the specified token that can be either ETH or any ERC20 token. The block number can be `nil`, -in which case the balance is taken from the latest known block. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------------- | -| `ctx` | `context.Context` | Context. | -| `token` | `common.Address` | L2 token address. | -| `at` | `*big.Int` | Block number. | - -```go -Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error) -``` - -#### Example - -```go -balance, err := account.Balance(context.Background(), utils.EthAddress, nil) -if err != nil { - log.Panic(err) -} -fmt.Println("Balance: ", balance) -``` - -### `AllBalances` - -Returns all balances for confirmed tokens given by an associated account. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------- | ----------- | -| `ctx` | `context.Context` | Context. | - -```go -AllBalances(ctx context.Context) (map[common.Address]*big.Int, error) -``` - -#### Example - -```go -balances, err := account.AllBalances(context.Background()) -if err != nil { - log.Panic(err) -} -fmt.Printf("Balances: %+v\n", balances) -``` - -### `Nonce` - -Returns the account nonce of the associated account. The block number can be `nil`, in which case the nonce is taken -from the latest known block. - -#### Inputs - -| Parameter | Type | Description | -| ------------- | --------------------- | ------------- | -| `ctx` | `context.Context` | Context. | -| `blockNumber` | `*big.Int` (optional) | Block number. | - -```go -Nonce(ctx context.Context, blockNumber *big.Int) (uint64, error) -``` - -#### Example - -```go -nonce, err := account.Nonce(context.Background(), big.NewInt(9000)) -if err != nil { - log.Panic(err) -} -fmt.Println("Nonce: ", nonce) -``` - -### `DeploymentNonce` - -Returns the deployment nonce of the account. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ------------------------------------------------ | ------------- | -| `opts` | [`CallOpts`](/sdk/go/api/accounts/types#callopts) (optional) | Call options. | - -```go -DeploymentNonce(opts *CallOpts) (*big.Int, error) -``` - -#### Example - -```go -deploymentNonce, err := account.DeploymentNonce(nil) -if err != nil { - log.Panic(err) -} -``` - -### `PopulateTransaction` - -Populates the transaction `tx` using the provided [`TransactionBuilder`](/sdk/go/api/accounts/types#transactionbuilder) function. -If `tx.From` is not set, it sets the value from the `Address()` method which can -be utilized in the `TransactionBuilder` function. - -#### Inputs - -| Parameter | Type | Description | -|-----------|----------------------------------------------------------|------------------------------------| -| `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be populated. | - -```go -PopulateTransaction(ctx context.Context, tx *zkTypes.Transaction712) error -``` - -#### Example - -```go -address := common.HexToAddress("") -tx := &zkTypes.Transaction712{ - To: &address, - Value: big.NewInt(7_000_000_000), -} - -err = account.PopulateTransaction(context.Background(), tx) -if err != nil { - log.Panic(err) -} -``` - -### `SignTransaction` - -Returns a signed transaction that is ready to be broadcast to -the network. The `PopulateTransaction` method is called first to ensure that all -necessary properties for the transaction to be valid have been populated. - -#### Inputs - -| Parameter | Type | Description | -|-----------|---------------------------------------------------------|------------------------------------------| -| `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be signed. | - -```go - -SignTransaction(ctx context.Context, tx *zkTypes.Transaction712) ([]byte, error) -``` - -#### Example - -```go -address := common.HexToAddress("") -signedTx, err := account.SignTransaction(context.Background(), &zkTypes.Transaction712{ - To: &address, - Value: big.NewInt(1_000_000_000_000_000_000), // 1ETH -}) -if err != nil { - log.Panic(err) -} -``` - -### `SendTransaction` - -Injects a transaction into the pending pool for execution. -The `SignTransaction` is called first to ensure transaction is properly signed. - -#### Inputs - -| Parameter | Type | Description | -|-----------|---------------------------------------------------------|------------------------------------------| -| `ctx` | `context.Context` | Context. | -| `tx` | [`*zkTypes.Transaction712`](/sdk/go/api/types#transaction712) | The transaction that needs to be signed. | - -```go -SendTransaction(ctx context.Context, tx *zkTypes.Transaction712) (common.Hash, error) -``` - -#### Example - -```go -address := common.HexToAddress("") -txHash, err := account.SendTransaction(context.Background(), &zkTypes.Transaction712{ - To: &address, - Value: big.NewInt(1_000_000_000_000_000_000), // 1ETH -}) -if err != nil { - log.Panic(err) -} -``` - -### `SignMessage` - -Signs a message using the provided [`PayloadSigner`](/sdk/go/api/accounts/types#payloadsigner) function. - -#### Inputs - -| Parameter | Type | Description | -|-----------|-------------------|--------------------------------------| -| `ctx` | `context.Context` | Context. | -| `message` | `[]byte` | The message that needs to be signed. | - -```go -SignMessage(ctx context.Context, message []byte) ([]byte, error) -``` - -#### Example - -```go -signature, err := account.SignMessage(context.Background(), []byte("Hello World!")) -if err != nil { - log.Panic(err) -} -``` - -### `SignTypedData` - -signs a typed data using the provided [`PayloadSigner`](/sdk/go/api/accounts/types#payloadsigner) function. - -#### Inputs - -| Parameter | Type | Description | -|-------------|-----------------------|-----------------------------------------| -| `ctx` | `context.Context` | Context. | -| `typedData` | `apitypes.TypedData` | The typed data that needs to be signed. | - -```go -SignTypedData(ctx context.Context, typedData apitypes.TypedData) ([]byte, error) -``` - -#### Example - -```go -signature, err := account.SignTypedData(context.Background(), apitypes.TypedData{ - Domain: apitypes.TypedDataDomain{ - Name: "Example", - Version: "1", - ChainId: math.NewHexOrDecimal256(270), - }, - Types: apitypes.Types{ - "Person": []apitypes.Type{ - {Name: "name", Type: "string"}, - {Name: "age", Type: "uint8"}, - }, - "EIP712Domain": []apitypes.Type{ - {Name: "name", Type: "string"}, - {Name: "version", Type: "string"}, - {Name: "chainId", Type: "uint256"}, - }, - }, - PrimaryType: "Person", - Message: apitypes.TypedDataMessage{ - "name": "John", - "age": hexutil.EncodeUint64(30), - }, -}) -if err != nil { - log.Panic(err) -} -``` - -### `Withdraw` - -Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network -to the target account on L1 network. - -#### Inputs - -| Parameter | Type | Description | -| --------- | --------------------------------------------------------------- | ---------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | -| `tx` | [`WithdrawalTransaction`](/sdk/go/api/accounts/types#withdrawaltransaction) | Withdrawal transaction parameters. | - -```go -Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (common.Hash, error) -``` - -#### Examples - -Withdraw ETH. - -```go -txHash, err := account.Withdraw(nil, accounts.WithdrawalTransaction{ - To: account.Address(), - Amount: big.NewInt(1_000_000_000_000_000_000), - Token: utils.LegacyEthAddress, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Withdraw transaction: ", txHash) -``` - -Withdraw ETH using paymaster to facilitate fee payment with an ERC20 token. - -```go -token := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F"); // Crown token which can be minted for free -paymaster := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46"); // Paymaster for Crown token - -paymasterParams, err := utils.GetPaymasterParams( - paymaster, - &zkTypes.ApprovalBasedPaymasterInput{ - Token: token, - MinimalAllowance: big.NewInt(1), - InnerInput: []byte{}, -}) -if err != nil { - log.Panic(err) -} - -txHash, err := account.Withdraw(nil, accounts.WithdrawalTransaction{ - To: account.Address(), - Amount: big.NewInt(1_000_000_000_000_000_000), - Token: utils.LegacyEthAddress, - PaymasterParams: paymasterParams, - }) -``` - -### `Transfer` - -Moves the ETH or any ERC20 token from the associated account to the target account. - -#### Inputs - -| Parameter | Type | Description | -| --------- | ----------------------------------------------------------- | -------------------------------- | -| `auth` | [`*TransactOpts`](/sdk/go/api/accounts/types#transactopts) (optional) | Transaction options. | -| `tx` | [`TransferTransaction`](/sdk/go/api/accounts/types#transfertransaction) | Transfer transaction parameters. | - -```go -Transfer(auth *TransactOpts, tx TransferTransaction) (common.Hash, error) -``` - -#### Examples - -Transfer ETH. - -```go -txHash, err := account.Transfer(nil, accounts.TransferTransaction{ - To: Address2, - Amount: amount, - Token: utils.LegacyEthAddress, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Transaction: ", txHash) -``` - -Transfer ETH using paymaster to facilitate fee payment with an ERC20 token. - -```go -token := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F"); // Crown token which can be minted for free -paymaster := common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46"); // Paymaster for Crown token - -paymasterParams, err := utils.GetPaymasterParams( - paymaster, - &zkTypes.ApprovalBasedPaymasterInput{ - Token: token, - MinimalAllowance: big.NewInt(1), - InnerInput: []byte{}, -}) -if err != nil { - log.Panic(err) -} - -txHash, err := account.Transfer(nil, accounts.TransferTransaction{ - To: Address2, - Amount: amount, - Token: utils.LegacyEthAddress, - PaymasterParams: paymasterParams, -}) -if err != nil { - log.Panic(err) -} -fmt.Println("Transaction: ", txHash) -``` diff --git a/content/sdk/20.go/02.api/05.types.md b/content/sdk/20.go/02.api/05.types.md index 9ec0559b..f980425b 100644 --- a/content/sdk/20.go/02.api/05.types.md +++ b/content/sdk/20.go/02.api/05.types.md @@ -1,5 +1,5 @@ --- -title: Types and Interfaces +title: Types description: Defines various types for ZKsync Go SDK. tags: ["go", "zksync", "sdk", "types"] ---