Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
docs: update for Go SDK for v0.4.0 release (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelTxFusion authored Mar 25, 2024
1 parent 7888fc9 commit 45fb64d
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 13 deletions.
31 changes: 27 additions & 4 deletions docs/build/sdks/go/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,29 @@ if err != nil {
}
```

### `DeploymentNonce`

Returns the deployment nonce of the account.

#### Inputs

| Parameter | Type | Description |
| --------- | --------------------------------------------------- | ------------- |
| `opts` | [`CallOpts`](types/accounts.md#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)
}
```

### `Withdraw`

Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network to the target account on
Expand Down Expand Up @@ -1168,7 +1191,7 @@ func NewBaseDeployer(adapter *AdapterL2) *BaseDeployer

### `Deploy`

Deploys smart contract using CREATE2 opcode.
Deploys smart contract using CREATE2 method.

#### Inputs

Expand Down Expand Up @@ -1199,7 +1222,7 @@ fmt.Println("Transaction: ", hash)

### `DeployWithCreate`

Deploys smart contract using CREATE opcode.
Deploys smart contract using CREATE method.

#### Inputs

Expand Down Expand Up @@ -1230,7 +1253,7 @@ fmt.Println("Transaction: ", hash)

### `DeployAccount`

Deploys smart account using CREATE2 opcode.
Deploys smart account using CREATE2 method.

#### Inputs

Expand Down Expand Up @@ -1274,7 +1297,7 @@ fmt.Println("Transaction: ", hash)

### `DeployAccountWithCreate`

Deploys smart account using CREATE opcode.
Deploys smart account using CREATE method.

#### Inputs

Expand Down
57 changes: 57 additions & 0 deletions docs/build/sdks/go/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -1033,3 +1033,60 @@ if err != nil {
}
fmt.Println("Gas: ", gas)
```

### `Proof`

Returns Merkle proofs for one or more storage values at the specified account along with a Merkle proof of their authenticity.

#### Inputs

| Parameter | Type | Description |
| --------------- | ----------------- | ----------------------------------------------------------------------------------------------- |
| `ctx` | `context.Context` | Context. |
| `address` | `common.Address` | The account to fetch storage values and proofs for. |
| `keys` | `common.Hahs` | Vector of storage keys in the account. |
| `l1BatchNumber` | `*big.Int` | Number of the L1 batch specifying the point in time at which the requested values are returned. |

```go
Proof(ctx context.Context, address common.Address, keys []common.Hash, l1BatchNumber *big.Int) (*zkTypes.StorageProof, error)
```

#### Example

```go
// Fetching the storage proof for rawNonces storage slot in NonceHolder system contract.
// mapping(uint256 => uint256) internal rawNonces;

baseClient, ok := client.(*clients.BaseClient)
if !ok {
log.Panic("casting could not be performed")
}

address := common.HexToAddress("<address>")

// Ensure the address is a 256-bit number by padding it
// because rawNonces slot uses uint256 for mapping addresses and their nonces.
addressPadded := common.LeftPadBytes(address.Bytes(), 32)

// Convert the slot number to a hex string and pad it to 32 bytes
slotBytes := common.Hex2Bytes("0x00") // slot with index 0
slotPadded := common.LeftPadBytes(slotBytes, 32)

// Concatenate the padded address and slot number
concatenated := append(addressPadded, slotPadded...)
storageKey := crypto.Keccak256(concatenated)

l1BatchNumber, err := client.L1BatchNumber(context.Background())
if err != nil {
log.Panic(err)
}

storageProof, err := baseClient.Proof(
context.Background(),
utils.NonceHolderAddress,
[]common.Hash{common.BytesToHash(storageKey)},
l1BatchNumber)
if err != nil {
log.Panic(err)
}
```
8 changes: 4 additions & 4 deletions docs/build/sdks/go/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ contracts and smart accounts. There are the following objects that implement the
Contract instantiation is the same as in the [`geth`](https://geth.ethereum.org/docs/developers/dapp-developer/native-bindings) library. For
examples of how to deploy and instantiate contracts and accounts, refer to the following:

- [Deploy smart contracts using CREATE opcode](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/09_deploy_create.go).
- [Deploy smart contracts using CREATE2 opcode](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/12_deploy_create2.go).
- [Deploy smart accounts using CREATE opcode](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/17_deploy_create_account.go).
- [Deploy smart accounts using CREATE2 opcode](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/18_deploy_create2_account.go).
- [Deploy smart contracts using CREATE method](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/08_deploy_create.go).
- [Deploy smart contracts using CREATE2 method](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/11_deploy_create2.go).
- [Deploy smart accounts using CREATE method](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/16_deploy_create_account.go).
- [Deploy smart accounts using CREATE2 method](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/17_deploy_create2_account.go).

## Contracts interfaces

Expand Down
10 changes: 5 additions & 5 deletions docs/build/sdks/go/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ Also, the following examples demonstrate how to:
1. [Deposit ETH and tokens from Ethereum into zkSync Era](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/01_deposit.go).
2. [Transfer ETH and tokens on zkSync Era](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/02_transfer.go).
3. [Withdraw ETH and tokens from zkSync Era to Ethereum](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/03_withdraw.go).
4. [Deploy a smart contract using CREATE opcode](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/09_deploy_create.go).
5. [Deploy a smart contract using CREATE2 opcode](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/12_deploy_create2.go).
6. [Deploy custom token on zkSync Era](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/15_deploy_token_create.go).
7. [Deploy smart account](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/17_deploy_create_account.go).
8. [Use paymaster to pay fee with token](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/19_use_paymaster.go).
4. [Deploy a smart contract using CREATE method](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/08_deploy_create.go).
5. [Deploy a smart contract using CREATE2 method](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/11_deploy_create2.go).
6. [Deploy custom token on zkSync Era](https://github.com/zksync-sdk/zksync2-examples/blob/main/go/14_deploy_token_create.go).
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). Examples are configured to
interact with `zkSync Era`, and `Sepolia` test networks.
17 changes: 17 additions & 0 deletions docs/build/sdks/go/types/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,23 @@ type StandardConfiguration struct {
}
```

### `StorageProof`

Merkle proofs for one or more storage values at the specified account

```go

type StorageProof struct {
Address string `json:"address"`
Proofs []struct {
Key string `json:"key"`
Proof []string `json:"proof"`
Value string `json:"value"`
Index int `json:"index"`
} `json:"storageProof"`
}
```

### `PaymasterParams`

Contains parameters for configuring the custom paymaster for the transaction.
Expand Down
6 changes: 6 additions & 0 deletions docs/build/sdks/go/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ ContractDeployerAddress := common.HexToAddress("0x000000000000000000000000000000
L1MessengerAddress := common.HexToAddress("0x0000000000000000000000000000000000008008")
```

#### Nonce holder

```go
NonceHolderAddress := common.HexToAddress("0x0000000000000000000000000000000000008003")
```

### Gas

#### `DefaultGasPerPubdataLimit`
Expand Down

0 comments on commit 45fb64d

Please sign in to comment.