# C++

The C++ SDK is the C++ client for the `antd` daemon.

## Install

```cmake
include(FetchContent)
FetchContent_Declare(
    antd-cpp
    GIT_REPOSITORY https://github.com/WithAutonomi/ant-sdk.git
    SOURCE_SUBDIR  antd-cpp
)
FetchContent_MakeAvailable(antd-cpp)

target_link_libraries(your_target PRIVATE antd)
```

## Connect to the daemon

```cpp
#include "antd/antd.hpp"

int main() {
    antd::Client client("http://localhost:8082");
    auto health = client.health();
    return health.ok ? 0 : 1;
}
```

## Store and retrieve data

```cpp
#include "antd/antd.hpp"
#include <iostream>

int main() {
    antd::Client client;
    std::string msg = "Hello, Autonomi!";
    std::vector<uint8_t> data(msg.begin(), msg.end());

    auto result = client.data_put_public(data);
    std::cout << result.address << std::endl;

    auto retrieved = client.data_get_public(result.address);
    std::string text(retrieved.begin(), retrieved.end());
    std::cout << text << std::endl;
}
```

## Type mappings

| Autonomi type  | C++ type                         |
| -------------- | -------------------------------- |
| `HealthStatus` | struct with `ok` and `network`   |
| `PutResult`    | struct with `cost` and `address` |
| Raw data       | `std::vector<uint8_t>`           |

## Error handling

```cpp
try {
    auto data = client.data_get_public("bad-address");
} catch (const antd::NotFoundError& e) {
    std::cerr << e.what() << std::endl;
} catch (const antd::PaymentError& e) {
    std::cerr << e.what() << std::endl;
} catch (const antd::AntdError& e) {
    std::cerr << e.what() << std::endl;
}
```

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