Skip to content

Commit

Permalink
fix(go): update examples to v0.4.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelTxFusion committed Feb 23, 2024
1 parent 3dd1a7d commit af94f61
Show file tree
Hide file tree
Showing 37 changed files with 968 additions and 2,494 deletions.
10 changes: 1 addition & 9 deletions go/09_deploy_create.go → go/08_deploy_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,12 @@ func main() {
fmt.Println("Transaction: ", hash)

// Wait unit transaction is finalized
_, err = client.WaitMined(context.Background(), hash)
receipt, err := client.WaitMined(context.Background(), hash)
if err != nil {
log.Panic(err)
}

receipt, err := client.TransactionReceipt(context.Background(), hash)
if err != nil {
log.Panic(err)
}
contractAddress := receipt.ContractAddress

if err != nil {
log.Panic(err)
}
fmt.Println("Smart contract address", contractAddress.String())

// INTERACT WITH SMART CONTRACT
Expand Down
32 changes: 0 additions & 32 deletions go/08_get_confirmed_tokens.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,12 @@ func main() {
fmt.Println("Transaction: ", hash)

// Wait unit transaction is finalized
_, err = client.WaitMined(context.Background(), hash)
receipt, err := client.WaitMined(context.Background(), hash)
if err != nil {
log.Panic(err)
}

receipt, err := client.TransactionReceipt(context.Background(), hash)
if err != nil {
log.Panic(err)
}
contractAddress := receipt.ContractAddress

if err != nil {
panic(err)
}
fmt.Println("Smart contract address: ", contractAddress.String())

// INTERACT WITH SMART CONTRACT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ func main() {
log.Panic(err)
}
contractAddress := receipt.ContractAddress

if err != nil {
log.Panic(err)
}
fmt.Println("Smart contract address: ", contractAddress.String())

// INTERACT WITH SMART CONTRACT
Expand Down
16 changes: 3 additions & 13 deletions go/12_deploy_create2.go → go/11_deploy_create2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/zksync-sdk/zksync2-go/accounts"
"github.com/zksync-sdk/zksync2-go/clients"
"github.com/zksync-sdk/zksync2-go/utils"
"log"
"math/big"
"os"
Expand Down Expand Up @@ -42,26 +41,17 @@ func main() {
//Deploy smart contract
hash, err := wallet.Deploy(nil, accounts.Create2Transaction{Bytecode: bytecode})
if err != nil {
panic(err)
log.Panic(err)
}
fmt.Println("Transaction: ", hash)

// Wait unit transaction is finalized
_, err = client.WaitMined(context.Background(), hash)
receipt, err := client.WaitMined(context.Background(), hash)
if err != nil {
log.Panic(err)
}

// Get address of deployed smart contract
contractAddress, err := utils.Create2Address(
wallet.Address(),
bytecode,
nil,
nil,
)
if err != nil {
log.Panic(err)
}
contractAddress := receipt.ContractAddress
fmt.Println("Smart contract address", contractAddress.String())

// INTERACT WITH SMART CONTRACT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/zksync-sdk/zksync2-go/accounts"
"github.com/zksync-sdk/zksync2-go/clients"
"github.com/zksync-sdk/zksync2-go/utils"
"log"
"math/big"
"os"
Expand Down Expand Up @@ -73,21 +72,12 @@ func main() {
fmt.Println("Transaction: ", hash)

// Wait unit transaction is finalized
_, err = client.WaitMined(context.Background(), hash)
receipt, err := client.WaitMined(context.Background(), hash)
if err != nil {
log.Panic(err)
}

// Get address of deployed smart contract
contractAddress, err := utils.Create2Address(
wallet.Address(),
bytecode,
constructor,
salt,
)
if err != nil {
panic(err)
}
contractAddress := receipt.ContractAddress
fmt.Println("Smart contract address: ", contractAddress.String())

// INTERACT WITH SMART CONTRACT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"crypto/rand"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/zksync-sdk/zksync2-go/accounts"
Expand Down Expand Up @@ -43,13 +44,21 @@ func main() {
log.Panic(err)
}

// Generate salt
salt := make([]byte, 32)
_, err = rand.Read(salt)
if err != nil {
log.Panicf("error while generating salt: %s", err)
}

// Deploy smart contract
hash, err := wallet.Deploy(nil, accounts.Create2Transaction{
Bytecode: demoBytecode,
Dependencies: [][]byte{fooBytecode},
Salt: salt,
})
if err != nil {
panic(err)
log.Panic(err)
}
fmt.Println("Transaction: ", hash)

Expand All @@ -59,12 +68,11 @@ func main() {
log.Panic(err)
}

// Get address of deployed smart contract
contractAddress, err := utils.Create2Address(
wallet.Address(),
demoBytecode,
nil,
nil,
salt,
)
if err != nil {
log.Panic(err)
Expand Down
20 changes: 11 additions & 9 deletions go/15_deploy_token_create.go → go/14_deploy_token_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/zksync-sdk/zksync2-go/accounts"
"github.com/zksync-sdk/zksync2-go/clients"
"github.com/zksync-sdk/zksync2-go/utils"
"log"
"os"
"zksync2-examples/contracts/crown"
"zksync2-examples/contracts/token"
)

func main() {
Expand All @@ -31,7 +30,7 @@ func main() {
log.Panic(err)
}

_, tokenAbi, bytecode, err := utils.ReadStandardJson("../solidity/custom_paymaster/token/build/Token.json")
tokenAbi, err := token.TokenMetaData.GetAbi()
if err != nil {
log.Panic(err)
}
Expand All @@ -42,35 +41,38 @@ func main() {
}

//Deploy smart contract
hash, err := wallet.DeployWithCreate(nil, accounts.CreateTransaction{Bytecode: bytecode, Calldata: constructor})
hash, err := wallet.DeployWithCreate(nil, accounts.CreateTransaction{
Bytecode: common.FromHex(token.TokenMetaData.Bin),
Calldata: constructor,
})
if err != nil {
log.Panic(err)
}
fmt.Println("Transaction: ", hash)

// Wait unit transaction is finalized
tx, err := client.WaitMined(context.Background(), hash)
receipt, err := client.WaitMined(context.Background(), hash)
if err != nil {
log.Panic(err)
}

// Get address of deployed smart contract
tokenAddress := tx.ContractAddress
tokenAddress := receipt.ContractAddress
fmt.Println("Token address", tokenAddress.String())

// Create instance of token contract
token, err := crown.NewCrown(tokenAddress, client)
tokenContract, err := token.NewToken(tokenAddress, client)
if err != nil {
log.Panic(err)
}

symbol, err := token.Symbol(nil)
symbol, err := tokenContract.Symbol(nil)
if err != nil {
log.Panic(err)
}
fmt.Println("Symbol: ", symbol)

decimals, err := token.Decimals(nil)
decimals, err := tokenContract.Decimals(nil)
if err != nil {
log.Panic(err)
}
Expand Down
31 changes: 11 additions & 20 deletions go/16_deploy_token_create2.go → go/15_deploy_token_create2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/zksync-sdk/zksync2-go/accounts"
"github.com/zksync-sdk/zksync2-go/clients"
"github.com/zksync-sdk/zksync2-go/utils"
"log"
"math/big"
"os"
"zksync2-examples/contracts/crown"
"zksync2-examples/contracts/token"
)

func main() {
Expand All @@ -33,8 +32,7 @@ func main() {
log.Panic(err)
}

// Read token contract from standard json
_, tokenAbi, bytecode, err := utils.ReadStandardJson("../solidity/custom_paymaster/token/build/Token.json")
tokenAbi, err := token.TokenMetaData.GetAbi()
if err != nil {
log.Panic(err)
}
Expand All @@ -45,43 +43,36 @@ func main() {
}

//Deploy smart contract
hash, err := wallet.Deploy(nil, accounts.Create2Transaction{Bytecode: bytecode, Calldata: constructor})
hash, err := wallet.Deploy(nil, accounts.Create2Transaction{
Bytecode: common.FromHex(token.TokenMetaData.Bin),
Calldata: constructor})
if err != nil {
log.Panic(err)
}
fmt.Println("Transaction: ", hash)

// Wait unit transaction is finalized
_, err = client.WaitMined(context.Background(), hash)
receipt, err := client.WaitMined(context.Background(), hash)
if err != nil {
log.Panic(err)
}

// Get address of deployed smart contract
tokenAddress, err := utils.Create2Address(
wallet.Address(),
bytecode,
constructor,
nil,
)
if err != nil {
log.Panic(err)
}
tokenAddress := receipt.ContractAddress
fmt.Println("Token address", tokenAddress.String())

// Create instance of token contract
token, err := crown.NewCrown(tokenAddress, client)
tokenContract, err := token.NewToken(tokenAddress, client)
if err != nil {
log.Panic(err)
}

symbol, err := token.Symbol(nil)
symbol, err := tokenContract.Symbol(nil)
if err != nil {
log.Panic(err)
}
fmt.Println("Symbol: ", symbol)

decimals, err := token.Decimals(nil)
decimals, err := tokenContract.Decimals(nil)
if err != nil {
log.Panic(err)
}
Expand All @@ -91,7 +82,7 @@ func main() {
if err != nil {
log.Panic(err)
}
mint, err := token.Mint(opts, wallet.Address(), big.NewInt(5))
mint, err := tokenContract.Mint(opts, wallet.Address(), big.NewInt(5))
if err != nil {
log.Panic(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ func main() {
fmt.Println("Transaction: ", hash)

// Wait unit transaction is finalized
_, err = client.WaitMined(context.Background(), hash)
receipt, err := client.WaitMined(context.Background(), hash)
if err != nil {
log.Panic(err)
}

receipt, err := client.TransactionReceipt(context.Background(), hash)
if err != nil {
log.Panic(err)
}
contractAddress := receipt.ContractAddress
fmt.Println("Paymaster address", contractAddress.String())
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ func main() {
fmt.Println("Transaction: ", hash)

// Wait unit transaction is finalized
_, err = client.WaitMined(context.Background(), hash)
receipt, err := client.WaitMined(context.Background(), hash)
if err != nil {
log.Panic(err)
}

// Get address of deployed smart contract
contractAddress, err := utils.Create2Address(wallet.Address(), bytecode, constructor, nil)
if err != nil {
log.Panic(err)
}
contractAddress := receipt.ContractAddress
fmt.Println("Paymaster address: ", contractAddress.String())
}
Loading

0 comments on commit af94f61

Please sign in to comment.