-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathbasic.go
More file actions
44 lines (39 loc) · 1.25 KB
/
basic.go
File metadata and controls
44 lines (39 loc) · 1.25 KB
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
package main
import (
"context"
"log"
"github.com/bnb-chain/greenfield-go-sdk/client"
"github.com/bnb-chain/greenfield-go-sdk/types"
)
func main() {
account, err := types.NewAccountFromPrivateKey("test", privateKey)
if err != nil {
log.Fatalf("New account from private key error, %v", err)
}
cli, err := client.New(chainId, rpcAddr, client.Option{DefaultAccount: account})
if err != nil {
log.Fatalf("unable to new greenfield client, %v", err)
}
ctx := context.Background()
nodeInfo, versionInfo, err := cli.GetNodeInfo(ctx)
if err != nil {
log.Fatalf("unable to get node info, %v", err)
}
log.Printf("nodeInfo moniker: %s, go version: %s", nodeInfo.Moniker, versionInfo.GoVersion)
latestBlock, err := cli.GetLatestBlock(ctx)
if err != nil {
log.Fatalf("unable to get latest block, %v", err)
}
log.Printf("latestBlock header: %s", latestBlock.Header)
heightBefore := latestBlock.Header.Height
log.Printf("Wait for block height: %d", heightBefore)
err = cli.WaitForBlockHeight(ctx, heightBefore+10)
if err != nil {
log.Fatalf("unable to wait for block height, %v", err)
}
height, err := cli.GetLatestBlockHeight(ctx)
if err != nil {
log.Fatalf("unable to get latest block height, %v", err)
}
log.Printf("Current block height: %d", height)
}