A high-performance Go client SDK for the Allora Network blockchain, providing comprehensive access to query services across Allora custom modules and Cosmos SDK base modules.
- Multi-endpoint support: Connect to multiple RPC endpoints with automatic load balancing
- Fault tolerance: Automatic failover and retry mechanisms with exponential backoff
- Health tracking: Built-in client health monitoring and automatic recovery
- Protocol abstraction: Currently supports gRPC, extensible for other protocols
- Comprehensive coverage: Query support for:
- Allora Emissions module (v9) - 100+ query methods
- Allora Mint module (v5) - 3 query methods
- Cosmos SDK Auth module - 5 query methods
- Cosmos SDK Bank module - 9 query methods
- Cosmos SDK Staking module - 14 query methods
- Tendermint/CometBFT service - 7 service methods
- Production ready: Comprehensive error handling, logging, and connection management
go get github.com/allora-network/allora-sdk-gopackage main
import (
"context"
"fmt"
"time"
"github.com/rs/zerolog"
allora "github.com/allora-network/allora-sdk-go"
)
func main() {
// Setup logger
logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
// Create client configuration with multiple endpoints for redundancy
config := &allora.ClientConfig{
Endpoints: []allora.EndpointConfig{
{
URL: "grpc://localhost:9090",
Protocol: "grpc",
},
{
URL: "grpc://backup.allora.com:9090",
Protocol: "grpc",
},
},
RequestTimeout: 30 * time.Second,
ConnectionTimeout: 10 * time.Second,
}
// Create the client
client, err := allora.NewClient(config, logger)
if err != nil {
logger.Fatal().Err(err).Msg("failed to create client")
}
defer client.Close()
ctx := context.Background()
// Get node information
nodeInfo, err := client.GetNodeInfo(ctx)
if err != nil {
logger.Error().Err(err).Msg("failed to get node info")
return
}
fmt.Printf("Connected to: %s\\n", nodeInfo.DefaultNodeInfo.Moniker)
// Get latest block
block, err := client.GetLatestBlock(ctx)
if err != nil {
logger.Error().Err(err).Msg("failed to get latest block")
return
}
fmt.Printf("Latest block height: %d\\n", block.SdkBlock.Header.Height)
// Get account balance
balance, err := client.BankBalance(ctx, "allo1...", "uallo")
if err != nil {
logger.Error().Err(err).Msg("failed to get balance")
return
}
fmt.Printf("Balance: %s\\n", balance.Balance.Amount)
// Get validators
validators, err := client.StakingValidators(ctx, "", &allora.PageRequest{Limit: 10})
if err != nil {
logger.Error().Err(err).Msg("failed to get validators")
return
}
fmt.Printf("Found %d validators\\n", len(validators.Validators))
}type ClientConfig struct {
// List of RPC endpoints to connect to
Endpoints []EndpointConfig
// Timeout for individual requests (default: 30s)
RequestTimeout time.Duration
// Connection timeout (default: 10s)
ConnectionTimeout time.Duration
}
type EndpointConfig struct {
// URL of the endpoint (e.g., "grpc://localhost:9090")
URL string
// Protocol to use ("grpc" is required for now)
Protocol string
}config := allora.DefaultClientConfig()
// Provides sensible defaults but you'll need to add endpoints
config.Endpoints = []allora.EndpointConfig{
{URL: "grpc://localhost:9090", Protocol: "grpc"},
}AuthAccount(ctx, address)- Get account informationAuthAccounts(ctx, pagination)- List all accountsAuthParams(ctx)- Get auth module parametersAuthModuleAccount(ctx, name)- Get module account by nameAuthModuleAccounts(ctx)- List all module accounts
BankBalance(ctx, address, denom)- Get account balance for specific denomBankAllBalances(ctx, address, pagination)- Get all balances for accountBankSpendableBalances(ctx, address, pagination)- Get spendable balancesBankTotalSupply(ctx, pagination)- Get total supply of all tokensBankSupplyOf(ctx, denom)- Get supply of specific denomBankParams(ctx)- Get bank module parametersBankDenomMetadata(ctx, denom)- Get metadata for specific denomBankDenomsMetadata(ctx, pagination)- Get metadata for all denomsBankDenomOwners(ctx, denom, pagination)- Get owners of specific denom
StakingValidators(ctx, status, pagination)- List validatorsStakingValidator(ctx, validatorAddr)- Get specific validatorStakingValidatorDelegations(ctx, validatorAddr, pagination)- Get validator delegationsStakingDelegation(ctx, delegatorAddr, validatorAddr)- Get specific delegationStakingDelegatorDelegations(ctx, delegatorAddr, pagination)- Get all delegator delegationsStakingPool(ctx)- Get staking pool informationStakingParams(ctx)- Get staking parameters- And more...
GetNodeInfo(ctx)- Get node informationGetSyncing(ctx)- Get sync statusGetLatestBlock(ctx)- Get latest blockGetBlockByHeight(ctx, height)- Get block by heightGetLatestValidatorSet(ctx, pagination)- Get latest validator setGetValidatorSetByHeight(ctx, height, pagination)- Get validator set by heightStatus(ctx)- Get node status
100+ query methods including:
EmissionsGetParams(ctx)- Get emissions parametersEmissionsGetTopic(ctx, topicId)- Get topic informationEmissionsGetTotalStake(ctx)- Get total stake in systemEmissionsTopicExists(ctx, topicId)- Check if topic existsEmissionsIsTopicActive(ctx, topicId)- Check if topic is active- And many more...
MintParams(ctx)- Get mint parametersMintInflation(ctx)- Get current inflation rateMintAnnualProvisions(ctx)- Get annual provisions
Note: Allora module methods currently return interface{} until protobuf types are generated. They will be updated to return strongly-typed responses in future versions.
The client automatically handles:
- Round-robin load balancing among healthy endpoints
- Automatic failover when endpoints become unavailable
- Exponential backoff for failed endpoints
- Health monitoring with automatic recovery
- Request retries with configurable timeouts
// Get health status of all clients in the pool
healthStatus := client.GetHealthStatus()
fmt.Printf("Active clients: %v\\n", healthStatus["active_clients"])
fmt.Printf("Cooling clients: %v\\n", healthStatus["cooling_clients"])The client provides comprehensive error handling:
balance, err := client.BankBalance(ctx, address, denom)
if err != nil {
// Handle different types of errors
switch {
case strings.Contains(err.Error(), "not found"):
fmt.Println("Account not found")
case strings.Contains(err.Error(), "connection refused"):
fmt.Println("Cannot connect to any endpoints")
default:
fmt.Printf("Other error: %v\\n", err)
}
return
}Many query methods support pagination:
// Get first 50 validators
validators, err := client.StakingValidators(ctx, "", &allora.PageRequest{
Limit: 50,
CountTotal: true,
})
// Get next page using key from previous response
if validators.Pagination.NextKey != nil {
nextValidators, err := client.StakingValidators(ctx, "", &allora.PageRequest{
Key: validators.Pagination.NextKey,
Limit: 50,
})
}make buildmake testmake lintmake proto-gen- Complete protobuf type generation for Allora modules
- Add support for JSON-RPC endpoints
- Add support for Cosmos LCD/REST endpoints
- Add caching layer for frequently accessed data
- Add metrics and monitoring integration
- Add transaction broadcasting support
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.