--value1
--value2
--value3
--value4
--value5
--value6
--accent1
--accent2
--accent3
--accent4
--accent5
--accent6
--logo1
--logo2
--logo3
--logo4
--logo5
--logo6

Rust IPFS Logo Rust IPFS

The performance and efficiency of Rust, and the decentralized power of IPFS.

Together at last.

Get Started

UnixFS Support

UnixFS

Easily encode your content and add, get, and cat to your heart's content

Global Swarming

Swarming

Connect to the global IPFS network and discover content via bootstrap peers

Canonical HTTP APIs

HTTP APIs

If your application already uses the IPFS HTTP APIs, you can easily switch to Rust IPFS

Getting Started

First, add ipfs and tokio to your Cargo.toml file:

[dependencies]
ipfs = "0.2.1"
tokio = { version = "0.2", features = ["full"] }
      

Then, in your src/main.rs:

use ipfs::{Ipfs, IpfsOptions, IpfsPath, TestTypes, UninitializedIpfs};
use std::process::exit;
use tokio::{io::AsyncWriteExt, stream::StreamExt};

#[tokio::main]
async fn main() {
    // Initialize an in-memory repo and start a daemon.
    let opts = IpfsOptions::inmemory_with_generated_keys();
    let (ipfs, fut): (Ipfs<TestTypes>, _) = UninitializedIpfs::new(opts).start().await.unwrap();

    // Spawn the background task
    tokio::task::spawn(fut);

    // Restore the default bootstrappers to enable content discovery
    ipfs.restore_bootstrappers().await.unwrap();

    // Get the IPFS README
    let path = "/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/readme"
        .parse::<IpfsPath>()
        .unwrap();

    let stream = ipfs.cat_unixfs(path, None).await.unwrap_or_else(|e| {
        eprintln!("Error: {}", e);
        exit(1);
    });

    tokio::pin!(stream);

    let mut stdout = tokio::io::stdout();

    loop {
        match stream.next().await {
            Some(Ok(bytes)) => {
                stdout.write_all(&bytes).await.unwrap();
            }
            Some(Err(e)) => {
                eprintln!("Error: {}", e);
                exit(1);
            }
            None => break,
        }
    }
}
      

Further Reading

These are some extra resources to get you started with specific use-cases of Rust IPFS:

This project is supported by

Equilibrium Protocol Labs Web3 Foundation

Rust IPFS is supported by Equilibrium, Protocol Labs, the Web3 Foundation, and YOU. If you find this work useful, please consider becoming a financial contributor on OpenCollective.