hApps

A hApp (short for ‘Holochain application’) is a package for distributing a full application. It bundles of one or more DNAs, along with an optional web-based user interface.

hApps: delivering a full package of functionality

As we described in Application Structure, a hApp is like a collection of microservices, each microservice’s role being filled by a DNA. A DNA may or may not be able to run independent from other DNAs, but a hApp should be able to be installed on a user’s computer and give them a fully working experience.

Create a hApp

The scaffolding tool is the easiest way to build out a full hApp with multiple DNAs and an optional GUI. Once you’ve got the Holochain dev shell working, open a terminal and enter this command:

nix run "github:/holochain/holonix?ref=main-0.4#hc-scaffold" -- web-app movies_happ

The tool will guide you through every step, from creating a bare working folder to creating individual data types and CRUD functions.

If you want to create your own project structure, enter this command in a dev shell:

hc app init movies_happ

This will prompt you for a name and description for your new hApp, then creates a folder called movies_happ that contains a basic happ.yaml file from your responses to the prompts.

Specify a hApp manifest

A hApp manifest is written in YAML. It contains metadata about the hApp, along with a list of roles filled by DNAs.

If you want to write your own, name it happ.yaml and give it the following structure. This example assumes that all of your bundled DNAs are in a folder called dnas/.

manifest_version: '1'
name: movies_happ
description: A movie encyclopedia and mutual lending application
roles:
- name: movies
  provisioning:
    strategy: create
    deferred: false
  dna:
    bundled: ./dnas/movies/movies.dna
    modifiers:
      network_seed: null
      properties: null
      origin_time: null
      quantum_time: null
    installed_hash: null
    clone_limit: 0
- name: lending
  provisioning:
    strategy: create
    deferred: false
  dna:
    bundled: ./dnas/lending/lending.dna
    modifiers:
      network_seed: null
      properties: null
      origin_time: null
      quantum_time: null
    installed_hash: null
    # The maximum number of clones, which is u32::MAX
    clone_limit: 4_294_967_295
allow_deferred_memproofs: false

hApp manifest structure at a glance

Create a web hApp

Most Holochain runtimes can serve a web-based GUI along with your hApp. You can design your front end any way you like, but it must have an index.html file and be packaged as a .zip file.

As usual, the scaffolding tool can handle this for you, and will build components for your entries, links, and collections using React, Svelte, Lit, Vue, or plain JavaScript. If you want to create your own folder structure, though, you can use the hc command. In a dev shell, enter:

hc web-app init movies_webhapp/

It’ll prompt you for a name, then create a folder with a web-happ.yaml.

Specify a web hApp manifest

If you want to write your own manifest, name it web-happ.yaml and give it the following structure.

manifest_version: '1'
name: movies_webhapp
ui:
  bundled: ./ui/ui.zip
happ_manifest:
  bundled: ./happ/movies_happ.happ

Web hApp manifest structure at a glance

Package a hApp for distribution

The first step to distributing your hApp is to bundle it into a .happ file, then bundle that file and a GUI into a .webhapp file. After that, you can go on to packaging it as a standalone binary or distributing it for runtimes that support multiple hApps.

To roll a hApp manifest and all its DNAs into a hApp bundle, use the hc command on a folder that contains a happ.yaml file:

hc app pack movies_happ/

This will create a file in the same folder as the happ.yaml, called <name>.happ, where <name> comes from the name field at the top of the manifest.

The next step, if you have a GUI, is to package the .happ file into a .webhapp:

hc web-app pack movies_webhapp/

Distributing for Holochain runtimes that support .hApp bundles

Your hApp is now ready to be distributed to people who run Holochain Launcher. If you turn on developer mode in the launcher’s settings, you can upload the bundle to the devHub and publish it on the hApp store. You can also offer it on the web for download and manual installation.

As a standalone binary

If you want to package a hApp as a standalone binary, along with the Holochain core library, you’ve got two options.

Reference

Further reading

It looks like you are using Internet Explorer. While the basic content is available, this is no longer a supported browser by the manufacturer, and no attention is being given to having IE work well here.