Official reference implementation for integrating hREA (Holochain Resource-Event-Agent) v0.3.1 into scaffolded Svelte Holochain applications. This project serves as the foundation for hREA's official get-started documentation and establishes the integration pattern for other frameworks.
š Version: This guide is specifically designed for hREA v0.3.1
This project demonstrates the clean, minimal approach to integrating hREA with scaffolded Holochain applications created using the official Holochain scaffolding tool. It provides a step-by-step example that will be used in the official hREA documentation and serves as the template for creating similar guides for Lit, non-scaffolded applications, and other frameworks.
š Prerequisites: This guide assumes you have already created a Holochain application using the official scaffolding tool with Svelte as the UI framework. If you haven't done this yet, follow the Holochain Development Environment setup and create a scaffolded app first.
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Svelte Frontend (UI) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Apollo Client + GraphQL (ValueFlows Schema) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Holochain Client (WebSocket) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā hREA DNA ā Custom DNA ā
ā (Economic Logic) ā (App-specific Logic) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
/ui
- Svelte frontend applicationsrc/contexts.ts
- Holochain and Apollo client managementsrc/ClientProvider.svelte
- Context provider for client connectionssrc/HREATest.svelte
- Basic example component demonstrating hREA operations/dnas/hc_test
- Custom Holochain DNA for app-specific logic/workdir
- Holochain application bundle configuration (includes hREA DNA)/tests
- Integration tests for the complete applicationThis guide assumes you already have a scaffolded Holochain application. If not, you need to:
Follow the official guide: Installing Holochain Development Environment
Create a new scaffolded web app:
nix run "github:/holochain/holonix?ref=main-0.5#hc-scaffold" -- web-app
Choose Svelte as your UI framework during scaffolding.
For hREA integration, ensure you also have:
# Add WebAssembly target for Rust
rustup target add wasm32-unknown-unknown
# Install Bun (if you chose it as package manager)
curl -fsSL https://bun.sh/install | bash
Note: These steps assume you already have a scaffolded Holochain app. If not, see the Prerequisites section above.
Navigate to your scaffolded app directory and follow the integration steps in the detailed tutorial:
workdir/happ.yaml
npm start # or your chosen package manager
This command will:
In the frontend, you'll see the basic hREA example that demonstrates:
Once you have the basic example working, you can:
ui/src/HREATest.svelte
to understand the integration# Build Rust zomes
bun run build:zomes
# Build complete hApp
bun run build:happ
# Build UI only
bun run --filter ui build
# Run integration tests
bun test
# Package for web deployment
bun run package
This project demonstrates the standard pattern for integrating hREA with Holochain applications:
// contexts.ts - The integration setup
- createClientStore() // Manages Holochain WebSocket connection
- initializeHREA() // Creates Apollo Client with hREA GraphQL schema
- getApolloClient() // Provides access to hREA operations
<script lang="ts">
import { getApolloClient } from "./contexts";
import { gql } from "@apollo/client/core";
const client = getApolloClient();
// Example: Create a person agent
const createPerson = async () => {
const result = await client.mutate({
mutation: gql`
mutation CreatePerson($person: AgentCreateParams!) {
createPerson(person: $person) {
agent { id name }
}
}
`,
variables: {
person: { name: "John Doe", note: "Example person" }
}
});
};
</script>
The basic example shows how to work with core ValueFlows entities:
# Number of Holochain agents (default: 2)
AGENTS=3
# Custom bootstrap port
BOOTSTRAP_PORT=8000
# Custom UI port
UI_PORT=5173
Edit workdir/happ.yaml
to modify:
get-port
to automatically find available portsbun run download-hrea
rustup target add wasm32-unknown-unknown
# Enable verbose logging
RUST_LOG=debug bun start
# Clean Holochain sandbox
hc sandbox clean
# Clean build artifacts
cargo clean
This Svelte implementation establishes the integration pattern that will be replicated for:
This project serves as the foundation for official hREA get-started documentation. To contribute:
This project is licensed under the MIT License - see the LICENSE file for details.
For questions and support: