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

Patch go examples to v0.4.0 version #17

Merged
merged 2 commits into from
Feb 23, 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
2 changes: 1 addition & 1 deletion .github/workflows/test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
docker-compose up -d
popd
- name: Run tests
run: cd go && go test ./test/...
run: cd go && make run-tests
2 changes: 1 addition & 1 deletion .github/workflows/test-js.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run tests
name: Run tests JS
on:
workflow_dispatch:
pull_request:
Expand Down
13 changes: 1 addition & 12 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,7 @@ jobs:
- name: Install Go
uses: actions/[email protected]
- name: Run gofmt
run: |
cd go
fmt_output=$(gofmt -l .)

if [ -n "$fmt_output" ]; then
echo "Code not formatted correctly:"
echo "$fmt_output"
exit 1
else
echo "Code is formatted correctly"
exit 0
fi
run: cd go && make check-format
lint-js:
name: Check code format for JavaScript
runs-on: ubuntu-latest
Expand Down
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
Loading
Loading