Dart SDK for the antd daemon — the gateway to the Autonomi decentralized network.
Add to your pubspec.yaml:
dependencies:
antd: ^0.1.0Or install via command line:
dart pub add antdimport 'dart:convert';
import 'dart:typed_data';
import 'package:antd/antd.dart';
void main() async {
final client = AntdClient();
try {
// Check daemon health
final health = await client.health();
print('OK: ${health.ok}, Network: ${health.network}');
// Store data
final result = await client.dataPutPublic(
Uint8List.fromList(utf8.encode('Hello, Autonomi!')),
);
print('Stored at ${result.address} (cost: ${result.cost} atto)');
// Retrieve data
final data = await client.dataGetPublic(result.address);
print('Retrieved: ${utf8.decode(data)}');
} on AntdError catch (e) {
print('Error: $e');
} finally {
client.close();
}
}The SDK includes a GrpcAntdClient class that provides the same async
methods as the REST AntdClient, but communicates over gRPC.
Add the gRPC dependencies (already included in pubspec.yaml):
dependencies:
grpc: ^4.0.1
protobuf: ^3.1.0Generate the Dart protobuf/gRPC stubs from the proto definitions:
# Install the Dart protoc plugin
dart pub global activate protoc_plugin
# Generate stubs into lib/src/generated/
protoc --dart_out=grpc:lib/src/generated \
-I../../antd/proto \
antd/v1/common.proto antd/v1/health.proto antd/v1/data.proto \
antd/v1/chunks.proto antd/v1/files.proto antd/v1/events.protoimport 'dart:convert';
import 'dart:typed_data';
import 'package:antd/src/grpc_client.dart';
void main() async {
final client = GrpcAntdClient.withChannel();
// Or custom host/port:
// final client = GrpcAntdClient(host: 'my-host', port: 50051);
try {
final health = await client.health();
print('OK: ${health.ok}, Network: ${health.network}');
final result = await client.dataPutPublic(
Uint8List.fromList(utf8.encode('Hello via gRPC!')),
);
print('Stored at ${result.address}');
final data = await client.dataGetPublic(result.address);
print('Retrieved: ${utf8.decode(data)}');
} on AntdError catch (e) {
print('Error: $e');
} finally {
await client.close();
}
}The GrpcAntdClient throws the same AntdError hierarchy as the REST client,
translating gRPC status codes to the appropriate error subclass.
Note: Wallet operations (address, balance, approve) and payment_mode are available via REST only.
The antd daemon must be running. Start it with:
ant dev start// Default: http://localhost:8082, 5 minute timeout
final client = AntdClient();
// Custom URL
final client = AntdClient(baseUrl: 'http://custom-host:9090');
// Custom timeout
final client = AntdClient(timeout: Duration(seconds: 30));
// Custom HTTP client (e.g. for testing)
final client = AntdClient(httpClient: myHttpClient);All methods return Future<T> and can throw AntdError subclasses.
| Method | Description |
|---|---|
health() |
Check daemon status |
| Method | Description |
|---|---|
dataPutPublic(data) |
Store public data |
dataGetPublic(address) |
Retrieve public data |
dataPutPrivate(data) |
Store encrypted private data |
dataGetPrivate(dataMap) |
Retrieve private data |
dataCost(data) |
Estimate storage cost — returns UploadCostEstimate with size, chunks, gas, payment mode |
| Method | Description |
|---|---|
chunkPut(data) |
Store a raw chunk |
chunkGet(address) |
Retrieve a chunk |
| Method | Description |
|---|---|
fileUploadPublic(path) |
Upload a file |
fileDownloadPublic(address, destPath) |
Download a file |
dirUploadPublic(path) |
Upload a directory |
dirDownloadPublic(address, destPath) |
Download a directory |
fileCost(path, {isPublic}) |
Estimate upload cost — returns UploadCostEstimate with size, chunks, gas, payment mode |
All errors extend AntdError which implements Exception:
try {
final data = await client.dataGetPublic(address);
} on NotFoundError catch (e) {
print('Data not found on network');
} on PaymentError catch (e) {
print('Insufficient funds');
} on AntdError catch (e) {
print('Error ${e.statusCode}: ${e.message}');
}| Error Type | HTTP Status | When |
|---|---|---|
BadRequestError |
400 | Invalid parameters |
PaymentError |
402 | Insufficient funds |
NotFoundError |
404 | Resource not found |
AlreadyExistsError |
409 | Resource exists |
ForkError |
409 | Version conflict |
TooLargeError |
413 | Payload too large |
InternalError |
500 | Server error |
NetworkError |
502 | Network unreachable |
See the example/ directory:
01_connect— Health check02_data— Public data storage and retrieval03_chunks— Raw chunk operations04_files— File and directory upload/download06_private_data— Private encrypted data storage