> For the complete documentation index, see [llms.txt](https://docs.kardiachain.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kardiachain.io/docs/archived-docs/golang-sdk.md).

# Golang SDK

Link to Github:<https://github.com/kardiachain/go-kaiclient/tree/v1.0.0>

## **Installation**

```
go get github.com/kardiachain/go-kaiclient
```

## **Initializing**

```go
func SetupKAIClient() (*Client, context.Context, error) {
ctx, _ := context.WithCancel(context.Background())
cfg := zapdriver.NewProductionConfig()
logger, err := cfg.Build()
if err != nil {
return nil, nil, fmt.Errorf("Failed to create logger: %v", err)
}
// defer logger.Sync()
client, err := NewKaiClient("http://10.10.0.251:8551", logger)
if err != nil {
return nil, nil, fmt.Errorf("Failed to create new KaiClient: %v", err)
}
return client, ctx, nil
}
```

## **Endpoints**&#x20;

### &#x20;    **LatestBlockNumber**

```go
LatestBlockNumber(ctx context.Context) (uint64, error)
```

&#x20;  &#x20;

### &#x20;   **BlockByHash**

```go
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
```

### &#x20;    **BlockByNumber**

```go
BlockByNumber(ctx context.Context, number uint64) (*types.Block, error)
```

###

### &#x20;   **BlockHeaderByNumber**

```go
BlockByNumber(ctx context.Context, number uint64) (*types.Block, error)
```

&#x20;

### &#x20;   **BlockHeaderByHash**

```go
BlockHeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
```

&#x20;

### &#x20;   **GetTransaction**

```go
GetTransaction(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
```

###

### &#x20;   **GetTransactionReceipt**

```go
GetTransactionReceipt(ctx context.Context, txHash common.Hash) (*kai.PublicReceipt, error)
```

&#x20;

### &#x20;   **BalanceAt**

```go
BalanceAt(ctx context.Context, account common.Address, blockHeightOrHash interface{}) (string, error)
```

###

### &#x20;   **NonceAt**

```go
NonceAt(ctx context.Context, account common.Address) (uint64, error)
```

###

### &#x20;    **SendRawTransaction**

```go
SendRawTransaction(ctx context.Context, tx *types.Transaction) error
```

&#x20;

### &#x20;   **Peers**

```go
Peers(ctx context.Context) ([]*types.PeerInfo, error)
```

&#x20;

### &#x20;   **NodeInfo**

```go
NodesInfo(ctx context.Context) ([]*types.NodeInfo, error)
```

&#x20;

### &#x20;   **Datadir**

```go
Datadir(ctx context.Context) (string, error)
```

###

### &#x20;   **Validator**

```go
Validator(ctx context.Context, rpcURL string) (*types.Validator, error) {}
```

&#x20;

### &#x20;   **Validators**

```go
Validators(ctx context.Context) ([]*types.Validator, error)
```
