1. Pick a package
| You want | Package |
|---|---|
| HoloNET to start its own Holochain conductor, on any OS (simplest) | NextGenSoftware.Holochain.HoloNET.Client: if no conductor is installed it downloads the official one the first time (AutoDownloadConductor, see Where the conductor comes from) |
| The same, but it must work offline or never download | NextGenSoftware.Holochain.HoloNET.Client.Embedded (bundles 0.7.1 and 0.7.0, Windows) |
| The same, with a smaller download | .Client.Embedded.Holochain071 or .Client.Embedded.Holochain070 |
To use a conductor you already run (hc sandbox, a launcher, a server) |
NextGenSoftware.Holochain.HoloNET.Client, with AutoStartHolochainConductor = false |
| Entry models and collections on top | the matching NextGenSoftware.Holochain.HoloNET.ORM* variant |
| Just save and load data | NextGenSoftware.Holochain.HoloNET.API |
| Multiplayer networking | NextGenSoftware.Holochain.HoloNET.HyperNET |
| Everything in one reference (Client, ORM, HyperNET) | NextGenSoftware.Holochain.HoloNET.HDK |
dotnet add package NextGenSoftware.Holochain.HoloNET.Client.Embedded
Use one variant per app. They have the same API and namespaces; only the bundled conductor differs. Every library comes in the same four variants (none, .Embedded, .Embedded.Holochain071, .Embedded.Holochain070); see Packages for the full list. The bundled conductors are Windows programs: on other systems use the package with no suffix and run your own conductor.
2. Which Holochain version?
Both are supported and tested on every release.
- 0.7.1 is the default, and the one to use for new hApps.
- 0.7.0 is for hApps built against hdk 0.7.0. A hApp built for 0.7.1 also runs on a 0.7.0 conductor (the OASIS hApp is tested this way).
With a dual-version Embedded package, choose the version per client:
var dna = new HoloNETDNA { EmbeddedHolochainVersion = EmbeddedHolochainVersion.V0_7_0 };
3. Install a hApp and call a zome function
The admin client does the whole Holochain 0.7 setup in one call:
- Generates an agent key.
- Installs the
.happ(or keeps it if it's already installed). - Enables it.
- Grants zome-call signing.
- Attaches an app interface and issues the app authentication token.
- Connects an app client.
using NextGenSoftware.Holochain.HoloNET.Client;
// Embedded package: HoloNET starts the bundled conductor on connect.
var admin = new HoloNETClientAdmin(new HoloNETDNA { HolochainConductorMode = HolochainConductorModeEnum.UseEmbedded });
await admin.ConnectAsync();
var app = await admin.InstallEnableSignAttachAndConnectToHappAsync("my-app", @"C:\hApps\my-app.happ", "my-role");
if (!app.IsAppConnected)
throw new Exception(app.Message);
IHoloNETClientAppAgent client = app.HoloNETClientAppAgent;
ZomeFunctionCallBackEventArgs result = await client.CallZomeFunctionAsync("my_zome", "create_thing", new { name = "hello" });
if (result.IsError)
Console.WriteLine(result.Message);
else
Console.WriteLine(result.ZomeReturnHash); // the new record's ActionHash
To use your own conductor (the non-Embedded package), point at its admin port and turn auto-start off:
var admin = new HoloNETClientAdmin(new HoloNETDNA
{
HolochainConductorAdminURI = "ws://localhost:65464",
AutoStartHolochainConductor = false,
AutoShutdownHolochainConductor = false
});
4. Go higher level
- No Rust, just data: see the HoloNET API guide.
csharp
await HoloNETAPI.SaveDataAsync("greeting", "hello");
string greeting = (await HoloNETAPI.LoadDataAsync("greeting")).Result;
- Your own entry types as C# classes: see the HoloNET ORM guide.
- Multiplayer: see the HyperNET guide.
5. Things that trip people up on Holochain 0.7
- ActionHash vs EntryHash. Updates and deletes take the ActionHash of the record (
result.ZomeReturnHashafter a create). The ORM handles this for you. - App authentication tokens. Since 0.6, every app-interface connection needs a token from the admin API.
InstallEnableSignAttachAndConnectToHappAsyncgets one. If you connect an app client yourself, calladmin.IssueAppAuthenticationTokenAsyncand setHoloNETDNA.AppAuthenticationToken. - Capability grants. Holochain 0.7 rejects unrestricted grants for zome-call signing. HoloNET defaults to
CapGrantAccessType.Assigned, which is correct. - Sync methods inside events. Every method has a sync version, and they are safe to call from inside HoloNET's own event handlers. Prefer the
Asyncversions anyway.
6. Logging
HoloNET logs to the console and to %APPDATA%\NextGenSoftware\HoloNET\Logs. Set this up with HoloNETDNA.LogToConsole, LogToFile, LogPath, FileLoggingMode and ConsoleLoggingMode, or pass your own ILogProvider to the client's constructor.