# 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)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kardiachain.io/docs/archived-docs/golang-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
