-
Notifications
You must be signed in to change notification settings - Fork 16
/
14_deploy_token_create.go
80 lines (68 loc) · 1.67 KB
/
14_deploy_token_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/zksync-sdk/zksync2-go/accounts"
"github.com/zksync-sdk/zksync2-go/clients"
"log"
"os"
"zksync2-examples/contracts/token"
)
func main() {
var (
PrivateKey = os.Getenv("PRIVATE_KEY")
ZkSyncEraProvider = "https://sepolia.era.zksync.dev"
)
// Connect to zkSync network
client, err := clients.Dial(ZkSyncEraProvider)
if err != nil {
log.Panic(err)
}
defer client.Close()
// Create wallet
wallet, err := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, nil)
if err != nil {
log.Panic(err)
}
tokenAbi, err := token.TokenMetaData.GetAbi()
if err != nil {
log.Panic(err)
}
constructor, err := tokenAbi.Pack("", "Crown", "Crown", uint8(18))
if err != nil {
log.Panic(err)
}
//Deploy smart contract
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
receipt, err := client.WaitMined(context.Background(), hash)
if err != nil {
log.Panic(err)
}
// Get address of deployed smart contract
tokenAddress := receipt.ContractAddress
fmt.Println("Token address", tokenAddress.String())
// Create instance of token contract
tokenContract, err := token.NewToken(tokenAddress, client)
if err != nil {
log.Panic(err)
}
symbol, err := tokenContract.Symbol(nil)
if err != nil {
log.Panic(err)
}
fmt.Println("Symbol: ", symbol)
decimals, err := tokenContract.Decimals(nil)
if err != nil {
log.Panic(err)
}
fmt.Println("Decimals: ", decimals)
}