-
Notifications
You must be signed in to change notification settings - Fork 6
Get Blockchain info
Yevhen edited this page Jun 22, 2021
·
8 revisions
package main
import (
"context"
"fmt"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// Get BlockInfo by height
height, err := client.Blockchain.GetBlockchainHeight(context.Background())
if err != nil {
fmt.Printf("Blockchain.GetBlockhainHeight returned error: %s", err)
return
}
fmt.Println(height)
}
- Following parameters required:
- Height - height of block to get info from
package main
import (
"context"
"fmt"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// height of block in blockchain
height := sdk.Height(1)
// Get BlockInfo by height
block, err := client.Blockchain.GetBlockByHeight(context.Background(), height)
if err != nil {
fmt.Printf("Blockchain.GetBlockByHeight returned error: %s", err)
return
}
fmt.Printf(block.String())
}
- Following parameters required:
- Height - height of block to get info from
- Limit - how many block infos to return
package main
import (
"context"
"fmt"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// height of block in blockchain
height := sdk.Height(1)
// how many BlockInfo's to return
limit := sdk.Amount(100)
// Get BlockInfo's by height with limit
blocks, err := client.Blockchain.GetBlocksByHeightWithLimit(context.Background(), height, limit)
if err != nil {
fmt.Printf("Blockchain.GetBlocksByHeightWithLimit returned error: %s", err)
return
}
for _, block := range blocks {
fmt.Printf("%s\n", block.String())
}
}
- Following parameters required:
- Height - height of block to get transactions from
package main
import (
"context"
"fmt"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// height of block in blockchain
height := sdk.Height(1)
// Get TransactionInfo's by block height
transactions, err := client.Blockchain.GetBlockTransactions(context.Background(), height)
if err != nil {
fmt.Printf("Blockchain.GetBlockTransactions returned error: %s", err)
return
}
for _, transaction := range transactions {
fmt.Printf("%s\n", transaction.String())
}
}
package main
import (
"context"
"fmt"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// Get score of blockchain
score, err := client.Blockchain.GetBlockchainScore(context.Background())
if err != nil {
fmt.Printf("Blockchain.GetBlockchainScore returned error: %s", err)
return
}
fmt.Printf("%s\n", score)
}
package main
import (
"context"
"fmt"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// Get storage of blockchain
storage, err := client.Blockchain.GetBlockchainStorage(context.Background())
if err != nil {
fmt.Printf("Blockchain.GetBlockchainStorage returned error: %s", err)
return
}
fmt.Printf("%s\n", storage)
}
- Home
- Installation
-
Examples
- Basic functions
- Get Accounts info
- Get Transactions info
- Get Mosaic info
- Get Mosaic Levy info
- Get Namespace info
- Get BlockChain info
- Get Network info
- Get Metadata info
- Get Nem Metadata info
- Get Account Properties info
- Get Exchange info
- Get SDA-SDA Exchange info
- Get Secret lock info
- Get Storage info
- Announces a transaction
- Websocket