Golang SDK
Old Doc

Installation

1
go get github.com/kardiachain/go-kaiclient
Copied!

Initializing

1
func SetupKAIClient() (*Client, context.Context, error) {
2
ctx, _ := context.WithCancel(context.Background())
3
cfg := zapdriver.NewProductionConfig()
4
logger, err := cfg.Build()
5
if err != nil {
6
return nil, nil, fmt.Errorf("Failed to create logger: %v", err)
7
}
8
// defer logger.Sync()
9
client, err := NewKaiClient("http://10.10.0.251:8551", logger)
10
if err != nil {
11
return nil, nil, fmt.Errorf("Failed to create new KaiClient: %v", err)
12
}
13
return client, ctx, nil
14
}
Copied!

Endpoints

LatestBlockNumber

1
LatestBlockNumber(ctx context.Context) (uint64, error)
Copied!

BlockByHash

1
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
Copied!

BlockByNumber

1
BlockByNumber(ctx context.Context, number uint64) (*types.Block, error)
Copied!

BlockHeaderByNumber

1
BlockByNumber(ctx context.Context, number uint64) (*types.Block, error)
Copied!

BlockHeaderByHash

1
BlockHeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
Copied!

GetTransaction

1
GetTransaction(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
Copied!

GetTransactionReceipt

1
GetTransactionReceipt(ctx context.Context, txHash common.Hash) (*kai.PublicReceipt, error)
Copied!

BalanceAt

1
BalanceAt(ctx context.Context, account common.Address, blockHeightOrHash interface{}) (string, error)
Copied!

NonceAt

1
NonceAt(ctx context.Context, account common.Address) (uint64, error)
Copied!

SendRawTransaction

1
SendRawTransaction(ctx context.Context, tx *types.Transaction) error
Copied!

Peers

1
Peers(ctx context.Context) ([]*types.PeerInfo, error)
Copied!

NodeInfo

1
NodesInfo(ctx context.Context) ([]*types.NodeInfo, error)
Copied!

Datadir

1
Datadir(ctx context.Context) (string, error)
Copied!

Validator

1
Validator(ctx context.Context, rpcURL string) (*types.Validator, error) {}
Copied!

Validators

1
Validators(ctx context.Context) ([]*types.Validator, error)
Copied!
Last modified 6mo ago