Holochain DHT development for distributed coordination. Activate when: (1) Building Holochain applications (hApps), (2) Writing Zome code in Rust, (3) Configuring conductor and lair-keystore, (4) Working with DHT entries and links, or (5) Setting up Holochain development environment.
Holochain is a framework for building fully distributed, peer-to-peer applications. It uses a distributed hash table (DHT) for data storage and validation without global consensus.
| Concept | Description |
|---|---|
| hApp | Holochain Application - a collection of DNAs |
| DNA | Distributed Network Architecture - defines data types and validation rules |
| Zome | A module within a DNA written in Rust/WASM |
| Entry | A piece of data stored on the DHT |
| Link | A directed connection between two entries |
| Agent | A participant in the network with a unique key pair |
| Conductor | Runtime that hosts hApps and manages connections |
| Lair | Key management service (lair-keystore) |
# flake.nix
{
inputs.holochain.url = "github:holochain/holochain";
devShells.default = pkgs.mkShell {
packages = [
holochain
lair-keystore
hc # Holochain CLI
];
};
}
cargo install holochain
cargo install lair_keystore
# Scaffold new project
hc scaffold web-app my-happ
# Structure created:
# my-happ/
# ├── dnas/
# │ └── my_dna/
# │ ├── workdir/
# │ └── zomes/
# │ └── coordinator/
# │ └── src/lib.rs
# ├── ui/
# └── workdir/
# Build the hApp
hc dna pack dnas/my_dna/workdir
hc app pack workdir
// zomes/coordinator/src/lib.rs
use hdk::prelude::*;
#[hdk_entry_helper]
pub struct Post {
pub title: String,
pub content: String,
}
#[hdk_extern]
pub fn create_post(post: Post) -> ExternResult<ActionHash> {
create_entry(&EntryTypes::Post(post.clone()))
}
#[hdk_extern]
pub fn get_post(action_hash: ActionHash) -> ExternResult<Option<Record>> {
get(action_hash, GetOptions::default())
}
#[hdk_extern]
pub fn get_all_posts() -> ExternResult<Vec<Record>> {
let path = Path::from("all_posts");
let links = get_links(path.path_entry_hash()?, LinkTypes::AllPosts, None)?;
let posts: Vec<Record> = links
.into_iter()
.filter_map(|link| get(link.target, GetOptions::default()).ok().flatten())
.collect();
Ok(posts)
}
#[hdk_entry_defs]
#[unit_enum(UnitEntryTypes)]
pub enum EntryTypes {
Post(Post),
Comment(Comment),
}
#[hdk_link_types]
pub enum LinkTypes {
AllPosts,
PostToComments,
}
# conductor-config.yaml
environment_path: /tmp/holochain