Autonomi
LearnBuildWho we ArePublicationsGet ANTStart a Node
  • Learn
  • Node
  • ANT Token
  • Developers
  • Developer Documentation
  • Getting Started
    • Installation Guide
  • Core Concepts
    • Data Types
    • Data Storage
    • BLS Keys
  • How To Guides
    • Quick Start Guide
    • Local Network Setup Guide
    • Payments Guide
    • Build Apps with Python
    • Build Apps with Rust
  • API Reference
    • API Reference Overview
    • Client API
      • Chunks
      • GraphEntry
      • Pointer
      • Register
      • Scratchpad
      • BLS Keys
      • Analyze
    • Node API
    • BLS Threshold Crypto
    • Self Encryption
    • Rust Crate API Reference
    • Python API Reference
Powered by GitBook

Get Involved

  • Start a Node
  • Discord
  • Forum

Follow Us

  • X
  • Reddit
  • LinkedIn
On this page
  • Client Methods
  • Example
Export as PDF
  1. API Reference
  2. Client API

Chunks

Chunks are native data types in the Autonomi Network:

  • Size: 4MB of raw bytes

  • Content-addressed: Address is the hash of its content

  • Immutable & self-verifiable: Once stored, data cannot be modified, and its integrity can be verified by computing the hash and comparing it to the address.

Client Methods

  • chunk_get Retrieves a chunk from the network by its address.

  • chunk_put Uploads a chunk to the network with payment handling. Returns the total cost and the chunk's address.

  • chunk_cost Estimates the storage cost for a chunk.

Example

use autonomi::Client;
use autonomi::client::payment::PaymentOption;
use autonomi::client::chunk::{Chunk, Bytes};
use test_utils::evm::get_funded_wallet;
use eyre::Result;

async fn chunk_put_example() -> 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!"));

    // Estimate cost
    let cost = client.chunk_cost(chunk.address()).await?;
    println!("Chunk 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 put cost: {put_cost}");

    // Allow time for replication
    tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;

    // Retrieve and verify the chunk
    let got = client.chunk_get(&addr).await?;
    assert_eq!(got, chunk.clone());
    println!("Chunk retrieved successfully");
    Ok(())
}
PreviousClient APINextGraphEntry

Last updated 3 months ago