Chunks
Client Methods
Examples
Basic Chunk Operations
use autonomi::Client;
use autonomi::client::payment::PaymentOption;
use autonomi::client::chunk::{Chunk, Bytes};
use test_utils::evm::get_funded_wallet;
use eyre::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Initialize a local client and test wallet
let client = Client::init_local().await?;
let wallet = get_funded_wallet();
// Create a chunk with some data
let chunk = Chunk::new(Bytes::from("Hello, world!"));
println!("Created chunk with size: {} bytes", chunk.size());
// Estimate cost before uploading
let cost = client.chunk_cost(chunk.address()).await?;
println!("Estimated storage cost: {cost}");
// Upload chunk with payment
let payment_option = PaymentOption::from(&wallet);
let (put_cost, addr) = client.chunk_put(&chunk, payment_option).await?;
assert_eq!(addr, *chunk.address());
println!("Chunk uploaded for: {put_cost} at address: {}", addr.to_hex());
// Wait for replication across the network
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
// Retrieve and verify the chunk
let retrieved_chunk = client.chunk_get(&addr).await?;
assert_eq!(retrieved_chunk, chunk);
println!("Chunk retrieved successfully, data: {}",
String::from_utf8_lossy(retrieved_chunk.value()));
Ok(())
}Batch Upload Operations
Error Handling
Advanced Configuration
Performance Tuning
Streaming Data
Rust
Size Limits and Best Practices
Last updated