For the complete documentation index, see llms.txt. This page is also available as Markdown.

C#

Use the C# SDK to store and retrieve data through a local daemon, a background service called antd. The asynchronous client supports REST and gRPC.

Install

Use .NET 8. Create a console project and add the Autonomi.Antd package from NuGet:

dotnet new console --framework net8.0 --name AutonomiExample
cd AutonomiExample
dotnet add package Autonomi.Antd

The package provides the Antd.Sdk namespace used below. Replace the contents of Program.cs with an example and run it with dotnet run. Examples on this page use Autonomi.Antd 0.2 with antd 0.14.

Connect to antd

Follow Start the Local Daemon to run antd before connecting.

using System;
using Antd.Sdk;

try
{
    using var client = AntdClient.CreateRest(baseUrl: "http://localhost:8082");
    var health = await client.HealthAsync();
    Console.WriteLine($"antd version: {health.Version}");
}
catch (AntdException exception)
{
    Console.Error.WriteLine($"antd request failed: {exception.Message}");
    Environment.ExitCode = 1;
}

Expected output:

Store and retrieve data

Start antd in a write-enabled mode before you upload. The public Autonomi Network requires wallet and Ethereum Virtual Machine (EVM) payment configuration. A local development network created with ant dev start includes that configuration.

Expected output:

Type mappings

Autonomi type
C# type

HealthStatus

HealthStatus

PutResult

PutResult

Raw data

byte[]

Error handling

An address with no stored data throws NotFoundException, a subclass of AntdException.

Output when the valid address is not stored:

External-signer finalize methods throw PartialUploadException, a subclass of NetworkException, when some chunks remain unstored; it carries ChunksStored, ChunksFailed, TotalChunks, Retryable, and RetentionKnown. When Retryable is true, repeating the same finalize call with the same upload ID stores the remainder without paying again; see the external-signer guide for the other cases.

Full API reference

For all available antd endpoints, see the REST API.

For access without a local service, see the native C# SDK. Its Autonomi.Ffi package does not provide the Antd.Sdk client API used here.

Last updated