-
Notifications
You must be signed in to change notification settings - Fork 7
Get Blockchain info
Alexander Popov edited this page Jun 11, 2019
·
8 revisions
package main
import (
"fmt"
"github.com/proximax-storage/go-xpx-catapult-sdk/sdk"
"context"
)
const (
// Catapult-api-rest server.
baseUrl = "http://localhost:3000"
// Types of network.
networkType = sdk.MijinTest
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(baseUrl, networkType, time.Second * 10)
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.GetBlockhainHeight(context.Background())
if err != nil {
fmt.Printf("Blockchain.GetBlockhainHeight returned error: %s", err)
return
}
fmt.Printf("%s\n", height)
}
- Param height - Block height
package main
import (
"fmt"
"github.com/proximax-storage/go-xpx-catapult-sdk/sdk"
"context"
"math/big"
)
const (
// Catapult-api-rest server.
baseUrl = "http://localhost:3000"
// Types of network.
networkType = sdk.MijinTest
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(baseUrl, networkType, time.Second * 10)
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 := big.NewInt(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())
}
- Param height - Block height
- Param limit - Number of following blocks to be returned.
package main
import (
"fmt"
"github.com/proximax-storage/go-xpx-catapult-sdk/sdk"
"context"
"math/big"
)
const (
// Catapult-api-rest server.
baseUrl = "http://localhost:3000"
// Types of network.
networkType = sdk.MijinTest
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(baseUrl, networkType, time.Second * 10)
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 := big.NewInt(1)
// how many BlockInfo's to return
limit := big.NewInt(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())
}
}
- Param height - Block height
package main
import (
"fmt"
"github.com/proximax-storage/go-xpx-catapult-sdk/sdk"
"context"
"math/big"
)
const (
// Catapult-api-rest server.
baseUrl = "http://localhost:3000"
// Types of network.
networkType = sdk.MijinTest
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(baseUrl, networkType, time.Second * 10)
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 := big.NewInt(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 (
"fmt"
"github.com/proximax-storage/go-xpx-catapult-sdk/sdk"
"context"
)
const (
// Catapult-api-rest server.
baseUrl = "http://localhost:3000"
// Types of network.
networkType = sdk.MijinTest
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(baseUrl, networkType, time.Second * 10)
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 (
"fmt"
"github.com/proximax-storage/go-xpx-catapult-sdk/sdk"
"context"
)
const (
// Catapult-api-rest server.
baseUrl = "http://localhost:3000"
// Types of network.
networkType = sdk.MijinTest
)
// Simple Account API request
func main() {
conf, err := sdk.NewConfig(baseUrl, networkType, time.Second * 10)
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