# Go

The Go SDK is the Go client for the `antd` daemon.

## Install

```bash
go get github.com/WithAutonomi/ant-sdk/antd-go
```

## Connect to the daemon

```go
package main

import (
    "context"
    "fmt"

    antd "github.com/WithAutonomi/ant-sdk/antd-go"
)

func main() {
    client := antd.NewClient(antd.DefaultBaseURL)
    ctx := context.Background()

    health, err := client.Health(ctx)
    if err != nil {
        panic(err)
    }
    fmt.Println(health.OK)

    discoveredClient, url := antd.NewClientAutoDiscover()
    _ = discoveredClient
    fmt.Println(url)
}
```

The SDK also includes a `GrpcClient` for the daemon's gRPC endpoint.

## Store and retrieve data

For upload examples in this section, start `antd` in a write-enabled mode first. On the default network, that means wallet plus EVM payment configuration. On a local devnet, `ant dev start` provisions that for you.

```go
package main

import (
    "context"
    "fmt"
    "log"

    antd "github.com/WithAutonomi/ant-sdk/antd-go"
)

func main() {
    client := antd.NewClient(antd.DefaultBaseURL)
    ctx := context.Background()

    result, err := client.DataPutPublic(ctx, []byte("Hello from Go!"))
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(result.Address)

    data, err := client.DataGetPublic(ctx, result.Address)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(string(data))
}
```

## Type mappings

| Autonomi type          | Go type                     |
| ---------------------- | --------------------------- |
| `HealthStatus`         | `antd.HealthStatus`         |
| `PutResult`            | `antd.PutResult`            |
| `WalletAddress`        | `antd.WalletAddress`        |
| `WalletBalance`        | `antd.WalletBalance`        |
| `PrepareUploadResult`  | `antd.PrepareUploadResult`  |
| `FinalizeUploadResult` | `antd.FinalizeUploadResult` |
| `PrepareChunkResult`   | `antd.PrepareChunkResult`   |
| Raw data               | `[]byte`                    |

`PrepareChunkResult` is returned by `PrepareChunkUpload`. When `AlreadyStored` is `true`, only `Address` and `AlreadyStored` are populated and there is no payment to make or finalize call to issue. Otherwise, `UploadID`, `Payments`, and `TotalAmount` describe the external-signer payment required before calling `FinalizeChunkUpload`. Requires antd 0.7.0 or later.

## Error handling

```go
package main

import (
    "context"
    "errors"
    "fmt"

    antd "github.com/WithAutonomi/ant-sdk/antd-go"
)

func main() {
    client := antd.NewClient(antd.DefaultBaseURL)
    _, err := client.DataGetPublic(context.Background(), "nonexistent_address")
    if err != nil {
        var notFound *antd.NotFoundError
        if errors.As(err, &notFound) {
            fmt.Println("Data not found")
            return
        }
        fmt.Println(err)
    }
}
```

## Full API reference

For all available daemon endpoints, see the [REST API](/developers/sdk/install/reference/rest-api.md).


---

# 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.autonomi.com/developers/sdk/install/reference/language-bindings/go.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.
