Skip to content

Commit

Permalink
feat(go): add changes related to v1 version
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelTxFusion committed Nov 6, 2024
1 parent 6646ef1 commit 4042fb1
Show file tree
Hide file tree
Showing 21 changed files with 1,222 additions and 698 deletions.
82 changes: 50 additions & 32 deletions content/20.go/30.guides/00.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ fmt.Printf("%+v\n", transactionByHash)

Also, the following examples demonstrate how to:

1. Deposit ETH and tokens from Ethereum into ZKsync Era
- Deposit ETH and tokens from Ethereum into ZKsync Era

::collapsible

```bash
```go
package main

import (
Expand Down Expand Up @@ -134,13 +134,13 @@ func main() {
defer ethClient.Close()

// Create wallet
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, ethClient)
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), client, ethClient)
if err != nil {
log.Panic(err)
}

// Show balance before deposit
balance, err := wallet.Balance(context.Background(), utils.EthAddress, nil)
balance, err := wallet.Balance(nil, utils.EthAddress)
if err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func main() {
log.Panic(err)
}

balance, err = wallet.Balance(context.Background(), utils.EthAddress, nil)
balance, err = wallet.Balance(nil, utils.EthAddress)
if err != nil {
log.Panic(err)
}
Expand All @@ -199,15 +199,17 @@ func main() {
fmt.Println("ClaimFailedDeposit hash: ", cfdTx.Hash())
*/
}
```

::

2. Transfer ETH and tokens on ZKsync Era
- Transfer ETH and tokens on ZKsync Era

::collapsible

```bash
```go
package main

import (
"context"
"fmt"
Expand All @@ -233,12 +235,12 @@ func main() {
}
defer client.Close()
// Create wallet
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey1), &client, nil)
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey1), client, nil)
if err != nil {
log.Panic(err)
}
// Show balances before transfer for both accounts
account1Balance, err := wallet.Balance(context.Background(), utils.EthAddress, nil)
account1Balance, err := wallet.Balance(nil, utils.EthAddress)
if err != nil {
log.Panic(err)
}
Expand All @@ -264,7 +266,7 @@ func main() {
log.Panic(err)
}
// Show balances after transfer for both accounts
account1Balance, err = wallet.Balance(context.Background(), utils.EthAddress, nil)
account1Balance, err = wallet.Balance(nil, utils.EthAddress)
if err != nil {
log.Panic(err)
}
Expand All @@ -275,13 +277,15 @@ func main() {
fmt.Println("Account1 balance after transfer: ", account1Balance)
fmt.Println("Account2 balance after transfer: ", account2Balance)
}
```

::
3. Withdraw ETH and tokens from ZKsync Era to Ethereum

::collapsible
- Withdraw ETH and tokens from ZKsync Era to Ethereum

```bash
::collapsible

```go
package main

import (
Expand Down Expand Up @@ -318,7 +322,7 @@ func main() {
defer ethClient.Close()

// Create wallet
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, ethClient)
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), client, ethClient)
if err != nil {
log.Panic(err)
}
Expand All @@ -339,14 +343,16 @@ func main() {
// Once the withdrawal transaction is submitted on L1, it needs to be finalized.
// To learn more about how to achieve this, please take a look at the 04_finalize_withdraw.go script.
}
```

::
4. Deploy a smart contract using CREATE method

::collapsible
- Deploy a smart contract using CREATE method

```bash
::collapsible

package main
```go
package main

import (
"context"
Expand Down Expand Up @@ -504,14 +510,15 @@ func main() {
}
fmt.Println("Value after second Set method execution: ", value)
}
```

::

5. Deploy a smart contract using CREATE2 method
- Deploy a smart contract using CREATE2 method

::collapsible

```bash
```go
package main

import (
Expand Down Expand Up @@ -607,12 +614,15 @@ func main() {
}
fmt.Println("Value after Set method execution: ", value)
}
```

::
6. Deploy custom token on ZKsync Era

- Deploy custom token on ZKsync Era

::collapsible

```bash
```go

package main

Expand Down Expand Up @@ -641,7 +651,7 @@ func main() {
defer client.Close()

// Create wallet
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, nil)
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), client, nil)
if err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -694,12 +704,15 @@ func main() {
}
fmt.Println("Decimals: ", decimals)
}
```

::
7. Deploy smart account

- Deploy smart account

::collapsible

```bash
```go

package main

Expand Down Expand Up @@ -729,7 +742,7 @@ func main() {
defer client.Close()

// Create wallet
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, nil)
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), client, nil)
if err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -763,12 +776,15 @@ func main() {
contractAddress := receipt.ContractAddress
fmt.Println("Paymaster address", contractAddress.String())
}
```

::
8. Use paymaster to pay fee with token

- Use paymaster to pay fee with token

::collapsible

```bash
```go

package main

Expand Down Expand Up @@ -808,7 +824,7 @@ func main() {
defer client.Close()

// Create wallet
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, nil)
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), client, nil)
if err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -849,7 +865,7 @@ func main() {
}

// Read tokenContract and ETH balances from user and paymaster accounts
balance, err := wallet.Balance(context.Background(), utils.EthAddress, nil)
balance, err := wallet.Balance(nil, utils.EthAddress)
if err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -941,6 +957,8 @@ func main() {
fmt.Println("Paymaster tokenContract balance after mint: ", tokenBalance)

}
```

::

::callout{icon="i-heroicons-light-bulb"}
Expand Down
21 changes: 13 additions & 8 deletions content/20.go/30.guides/01.features.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ You can look at the internal structure of the EIP-712 transactions in the
This document will focus solely on how to pass these arguments to the SDK.
::

## EIP-712 Metadata
## EIP-712 support

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

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

## Encoding paymaster params

Expand Down Expand Up @@ -61,8 +59,15 @@ if err != nil {
}
defer client.Close()


ethClient, err := ethclient.Dial(EthereumProvider)
if err != nil {
log.Panic(err)
}
defer ethClient.Close()

// Create wallet
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, ethClient)
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), client, ethClient)
if err != nil {
log.Panic(err)
}
Expand Down
Loading

0 comments on commit 4042fb1

Please sign in to comment.