Quick Start Guide

This section will help you get started on your Autonomi adventure as quickly as possible. It will walk you through setting up your development environment and writing a simple Autonomi app.

My first App

Let's get right to it and build your first Autonomi app!

Add Autonomi as a Dependency

First import our Autonomi dependency using the language you love:

cargo add autonomi

Setup a Client

To connect to the Autonomi network, we'll need a `Client`:

use autonomi::Client;

#[tokio::main]
async fn main() {
    let client = Client::init()
        .await
        .expect("Could not initialize the client");
}

Download a Dog Picture

What better way is there to show off the capabilities of the network? Let's download a dog picture from this public data address:

a7d2fdbb975efaea25b7ebe3d38be4a0b82c1d71e9b89ac4f37bc9f8677826e0
use autonomi::client::address::str_to_addr;
use autonomi::Client;

#[tokio::main]
async fn main() {
    let client = Client::init()
        .await
        .expect("Could not initialize the client");

    // Data address of the dog picture
    let data_address =
        str_to_addr("a7d2fdbb975efaea25b7ebe3d38be4a0b82c1d71e9b89ac4f37bc9f8677826e0")
            .expect("Invalid data address");

    // Get the bytes of the dog picture
    let bytes = client
        .data_get_public(&data_address)
        .await
        .expect("Could not fetch data from the network");

    // Write the bytes of the dog picture to a file
    std::fs::write("lucky.jpg", bytes).expect("Failed to write the file");
}

After running this code, you'll see a lucky.jpg file downloaded to your work directory!

Last updated