> For the complete documentation index, see [llms.txt](https://docs.autonomi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.autonomi.com/developers/sdk/install/reference/language-bindings/go.md).

# 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!"),
        antd.PaymentModeAuto,
    )
    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` for chunk writes |
| `DataPutPublicResult`  | `antd.DataPutPublicResult`        |
| `DataPutResult`        | `antd.DataPutResult`              |
| `FilePutPublicResult`  | `antd.FilePutPublicResult`        |
| `FilePutResult`        | `antd.FilePutResult`              |
| `PaymentMode`          | `antd.PaymentMode`                |
| `UploadCostEstimate`   | `antd.UploadCostEstimate`         |
| `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).
