-
Notifications
You must be signed in to change notification settings - Fork 9
Examples: Get BlockChain info
Eleazar Garrido edited this page Jan 13, 2019
·
9 revisions
- Param height - Block height
package main
import (
"encoding/json"
"fmt"
"github.com/proximax-storage/nem2-sdk-go/sdk"
"golang.org/x/net/context"
"math/big"
)
// Simple Blockchain API request
func main() {
conf, err := sdk.NewConfig("http://localhost:3000",sdk.MijinTest)
if err != nil {
panic(err)
}
// Use the default http client
client := sdk.NewClient(nil, conf)
height := big.NewInt(1)
getBlockByHeight, err := client.Blockchain.GetBlockByHeight(context.Background(), height)
if err != nil {
fmt.Printf("Blockchain.GetBlockByHeight returned error: %s", err)
return
}
getBlockByHeightJson, _ := json.MarshalIndent(getBlockByHeight, "", " ")
fmt.Printf("%s\n\n", string(getBlockByHeightJson))
}
- Param height - Block height
height := big.NewInt(1)
getBlockTransactions, err := client.Blockchain.GetBlockTransactions(context.Background(), height)
if err != nil {
fmt.Printf("Blockchain.GetBlockTransactions returned error: %s", err)
return
}
fmt.Printf("%s\n\n", getBlockTransactions)
getBlockchainHeight, err := client.Blockchain.GetBlockchainHeight(context.Background())
if err != nil {
fmt.Printf("Blockchain.GetBlockchainHeight returned error: %s", err)
return
}
fmt.Printf("%s\n\n", getBlockchainHeight)
getBlockchainScore, err := client.Blockchain.GetBlockchainScore(context.Background())
if err != nil {
fmt.Printf("Blockchain.GetBlockchainScore returned error: %s", err)
return
}
fmt.Printf("%s\n\n", getBlockchainScore)
- Param height - Block height
- Param limit - Number of following blocks to be returned.
height := big.NewInt(1)
limit := big.NewInt(100)
getBlockchainInfo, err := client.Blockchain.GetBlocksByHeightWithLimit(context.Background(), height, limit)
if err != nil {
fmt.Printf("Blockchain.GetBlockchainInfo returned error: %s", err)
return
}
fmt.Printf("%s\n\n", getBlockchainInfo)
getBlockchainStorage, err := client.Blockchain.GetBlockchainStorage(context.Background())
if err != nil {
fmt.Printf("Blockchain.GetBlockchainStorage returned error: %s", err)
return
}
getBlockchainStorageJson, _ := jsoniter.MarshalIndent(getBlockchainStorage, "", " ")
fmt.Printf("%s\n\n", getBlockchainStorageJson)
}