Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Go: Add Bridgehub documentation #9

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 207 additions & 6 deletions content/sdk/11.go/03.clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ ZkSyncEraProvider := "https://testnet.era.zksync.dev"
ZkSyncEraWSProvider := "ws://testnet.era.zksync.dev:3051"

// Connect to zkSync network
client, err := clients.Dial(ZkSyncEraProvider)
client, err := clients.DialBase(ZkSyncEraProvider)
if err != nil {
log.Panic(err)
}
defer client.Close()

// Connect to zkSync network using Web Socket
wsClient, err := clients.Dial(ZkSyncEraWSProvider)
wsClient, err := clients.DialBase(ZkSyncEraWSProvider)
if err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -448,6 +448,30 @@ if err != nil {
}
```

### `BridgehubContractAddress`

Returns the Bridgehub smart contract address.

#### Inputs

| Parameter | Type | Description |
| --------- | ----------------- | ----------- |
| `ctx` | `context.Context` | Context. |

```go
BridgehubContractAddress(ctx context.Context) (common.Address, error)
```

#### Example

```go
address, err := client.BridgehubContractAddress(context.Background())
if err != nil {
log.Panic()
}
fmt.Println("Bridgehub address: ", address)
```

### `MainContractAddress`

Returns the address of the zkSync Era contract.
Expand Down Expand Up @@ -520,6 +544,82 @@ if err != nil {
fmt.Println("Bridge contracts: ", contracts)
```

### `BaseTokenContractAddress`

Returns the L1 base token address.

#### Inputs

| Parameter | Type | Description |
| --------- | ----------------- | ----------- |
| `ctx` | `context.Context` | Context. |

```go
BaseTokenContractAddress(ctx context.Context) (common.Address, error)
```

#### Example

```go
address, err := client.BaseTokenContractAddress(context.Background())
if err != nil {
log.Panic(err)
}
fmt.Println("Base token address: ", address)
```

### `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 := client.IsEthBasedChain(context.Background())
if err != nil {
log.Panic(err)
}
fmt.Println("Is ETH-based chain: ", isEthBased)
```

### `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 := client.IsBaseToken(
context.Background(),
common.HexToAddress("0x5C221E77624690fff6dd741493D735a17716c26B")
)
if err != nil {
log.Panic(err)
}
fmt.Println("Is base token: ", isBaseToken)
```

### `ContractAccountInfo`

Returns the version of the supported account abstraction and nonce ordering from a given contract address.
Expand Down Expand Up @@ -696,6 +796,75 @@ if err != nil {
fmt.Printf("Transaction details: %+v\n", *txDetails)
```

### `BytecodeByHash`

returns bytecode of a contract given by its hash.

#### Inputs

| Parameter | Type | Description |
|----------------| ----------------- |----------------|
| `ctx` | `context.Context` | Context. |
| `bytecodeHash` | `common.Hash` | Bytecode hash. |

```go
BytecodeByHash(ctx context.Context, bytecodeHash common.Hash) ([]byte, error)
```

#### Example

```go
testnetPaymaster, err := client.TestnetPaymaster(context.Background())
if err != nil {
log.Panic(err)
}
testnetPaymasterBytecode, err := client.CodeAt(context.Background(), testnetPaymaster, nil)
if err != nil {
log.Panic(err)
}

testnetPaymasterBytecodeHash, err := utils.HashBytecode(testnetPaymasterBytecode)
if err != nil {
log.Panic(err)
}

bytecode, err := client.BytecodeByHash(context.Background(), common.BytesToHash(testnetPaymasterBytecodeHash))
if err != nil {
log.Panic(err)
}
fmt.Println("Bytecode: ", bytecode)
```

### `RawBlockTransactions`

Returns data of transactions in a block.

#### Inputs

| Parameter | Type | Description |
|-----------|-------------------|---------------|
| `ctx` | `context.Context` | Context. |
| `number` | `uin64` | Block number. |

```go
RawBlockTransactions(ctx context.Context, number uint64) ([]zkTypes.RawBlockTransaction, error)
```

#### Example

```go
blockNumber, err := client.BlockNumber(context.Background())
if err != nil {
log.Panic(err)
}

rawBlockTransactions, err := client.RawBlockTransactions(context.Background(), blockNumber)
if err != nil {
log.Panic(err)
}
fmt.Println("Raw block transactions: ", rawBlockTransactions)
```

### `LogProof`

Returns the proof for a transaction's L2 to L1 log sent via the L1Messenger system contract.
Expand Down Expand Up @@ -761,6 +930,38 @@ if err != nil {
fmt.Printf("L2 transaction: %+v\n", l2Tx)
```

### `PriorityOpConfirmation`

Returns the transaction confirmation data that is part of `L2->L1` message.
The txHash is the hash of the L2 transaction where the message was initiated.
The index is used in case there were multiple transactions in one message, you may pass an index of the
transaction which confirmation data should be fetched.

#### Inputs

| Parameter | Type | Description |
|-----------|-------------------|--------------------|
| `ctx` | `context.Context` | Context. |
| `txHash` | `common.Hash` | Transaction hash. |
| `index` | `int` | Transaction index. |

```go
PriorityOpConfirmation(ctx context.Context, txHash common.Hash, index int) (*zkTypes.PriorityOpConfirmation, error)
```

#### Example

```go
// Any L2 -> L1 transaction can be used.
// In this case, withdrawal transaction is used.
txHash := common.HexToHash("0x2a1c6c74b184965c0cb015aae9ea134fd96215d2e4f4979cfec12563295f610e")
l1Receipt, err := client.PriorityOpConfirmation(context.Background(), txHash, 0)
if err != nil {
log.Panic(err)
}
fmt.Printf("Confirmation data: %+v\n", *l2Tx)
```

### `ConfirmedTokens`

Returns {address, symbol, name, and decimal} information of all tokens within a range of ids given by
Expand Down Expand Up @@ -800,9 +1001,9 @@ ETH address is set to zero address.
#### Inputs

| Parameter | Type | Description |
| --------- | ----------------- | ----------------- |
|-----------| ----------------- | ----------------- |
| `ctx` | `context.Context` | Context. |
| `address` | `common.Address` | L1 token address. |
| `token` | `common.Address` | L1 token address. |

```go
L2TokenAddress(ctx context.Context, token common.Address) (common.Address, error)
Expand All @@ -827,9 +1028,9 @@ ETH address is set to zero address.
#### Inputs

| Parameter | Type | Description |
| --------- | ----------------- | ----------------- |
|-----------| ----------------- | ----------------- |
| `ctx` | `context.Context` | Context. |
| `address` | `common.Address` | L2 token address. |
| `token` | `common.Address` | L2 token address. |

```go
L1TokenAddress(ctx context.Context, token common.Address) (common.Address, error)
Expand Down
Loading
Loading