# Zig

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

## Install

```zig
.dependencies = .{
    .antd = .{
        .url = "https://github.com/WithAutonomi/ant-sdk/archive/<commit>.tar.gz",
        .hash = "...",
    },
},
```

## Connect to the daemon

```zig
const std = @import("std");
const antd = @import("antd");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    var client = antd.Client.init(allocator, antd.default_base_url);
    defer client.deinit();

    const status = try client.health();
    defer status.deinit(allocator);
    std.debug.print("{s}\n", .{status.network});
}
```

## Store and retrieve data

```zig
const std = @import("std");
const antd = @import("antd");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    var client = antd.Client.init(allocator, antd.default_base_url);
    defer client.deinit();

    const result = try client.dataPutPublic("Hello, Autonomi!");
    defer result.deinit(allocator);
    std.debug.print("{s}\n", .{result.address});

    const data = try client.dataGetPublic(result.address);
    defer allocator.free(data);
    std.debug.print("{s}\n", .{data});
}
```

## Type mappings

| Autonomi type  | Zig type     |
| -------------- | ------------ |
| `HealthStatus` | Zig struct   |
| `PutResult`    | Zig struct   |
| Raw data       | `[]const u8` |

## Error handling

```zig
const result = client.dataPutPublic("data") catch |err| switch (err) {
    error.NotFound => return err,
    error.Payment => return err,
    else => return err,
};
_ = result;
```

## 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/zig.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.
