Runnable example: examples/01-Client (connecting, installing, zome calls, signals and admin calls). Tutorials: learn.holonet.oasisomniverse.one.
The two clients
| Class | Connects to | Used for |
|---|---|---|
HoloNETClientAdmin |
the conductor's admin interface | installing and managing hApps, agents, interfaces, grants, tokens, diagnostics |
HoloNETClientAppAgent |
an app interface, for one installed app | zome calls, signals, clone cells, app info |
Both take an optional HoloNETDNA (the settings) and an optional logger in their constructors.
Settings: HoloNETDNA
The most used settings:
| Setting | Default | Meaning |
|---|---|---|
HolochainConductorAdminURI |
ws://localhost:7777 |
The admin interface to connect to. |
HolochainConductorAppAgentURI |
ws://localhost:8888 |
The app interface (set for you by the install-and-connect helper). |
HolochainConductorMode |
UseSystemGlobal |
UseEmbedded starts the conductor an .Embedded package bundles. UseExternal starts one at FullPathToExternalHolochainConductorBinary. UseSystemGlobal uses the holochain on your PATH. |
EmbeddedHolochainVersion |
V0_7_1 |
Which bundled conductor to start (dual-version Embedded package). |
AutoStartHolochainConductor / AutoShutdownHolochainConductor |
true |
Start the conductor on connect and stop it on disconnect. Turn both off for a conductor you run yourself. |
AutoDownloadConductor |
true |
When a conductor is needed and none is installed, download the official one for this OS and CPU (SHA-256 checked) the first time. Set false on machines that must not download. See Where the conductor comes from. |
HolochainConductorVersion |
empty | Which Holochain release to download, for example "0.7.1". Empty uses EmbeddedHolochainVersion. |
AllowUnverifiedConductorDownload |
false |
Download a release with no known SHA-256 unchecked. Leave off. |
AppAuthenticationToken |
none | The app-interface token (Holochain 0.6+). Issued for you by the helper. |
InstalledAppId, AgentPubKey, DnaHash, CellId |
found after connect | Which app and cell zome calls go to. |
LogToConsole, LogToFile, LogPath, FileLoggingMode |
on, AppData | Logging. |
HoloNETDNAManager loads and saves these as HoloNETDNA.json if you want them in a file.
Connecting
var admin = new HoloNETClientAdmin(new HoloNETDNA { HolochainConductorMode = HolochainConductorModeEnum.UseEmbedded });
HoloNETConnectedEventArgs connected = await admin.ConnectAsync();
The one-call install. InstallEnableSignAttachAndConnectToHappAsync(appId, happPath, roleName) does every step Holochain 0.7 needs:
- Generates an agent key and installs the app. An app that's already installed is kept, with its agent, unless you pass
uninstallhAppIfAlreadyInstalled: true. - Enables it.
- Creates signing credentials and an assigned zome-call grant.
- Attaches an app interface.
- Issues an app authentication token.
- Returns a connected
HoloNETClientAppAgentinHoloNETClientAppAgent.
Use InstallEnableSignAndAttachHappAsync if you want to connect the app client yourself.
Connecting an app client manually:
var token = await admin.IssueAppAuthenticationTokenAsync("my-app");
var client = new HoloNETClientAppAgent("my-app", agentPubKey, new HoloNETDNA
{
AppAuthenticationToken = token.TokenIssued.token,
AutoStartHolochainConductor = false
});
await client.ConnectAsync("my-app", "ws://localhost:" + appPort);
await client.WaitTillReadyForZomeCallsAsync();
Zome calls
ZomeFunctionCallBackEventArgs r = await client.CallZomeFunctionAsync("zome", "function", new { field = "value" });
- What you pass.
paramsObjectcan be an anonymous object, a dictionary, a class or a primitive. It's serialised to MessagePack using its field names. - What comes back. The decoded return value is in
ZomeReturnValueandZomeReturnData, and the record hash inZomeReturnHash.Recordsholds decoded Holochain records. PassentryDataObjectTypeReturnedFromZometo have entries mapped onto your type. - Errors.
IsErrorandMessagetell you if the conductor or your zome returned an error. Calls never throw for zome errors. - Callbacks and ids. Overloads take a callback and/or a request
idso you can match responses yourself.ConductorResponseCallBackMode.UseCallBackEventsfiresOnZomeFunctionCallBackinstead of waiting.
Signals
- Emitted signals. When your zome calls
emit_signal,client.OnSignalCallBackfires.e.RawSignalData.Dataholds the raw MessagePack bytes, and the decoded forms are on the event args. - Remote signals between agents. These use
send_remote_signalandrecv_remote_signalin your zome. The OASIS hApp'shypernet_*functions are a ready-made example: HyperNET and HoloNET API signals are built on them. - Direct signals between apps.
GrantDirectSignalCapabilityAsyncandSendDirectSignalAsyncsend these.
The admin API
All of these have Async and sync versions:
| Area | Methods |
|---|---|
| Agents | GenerateAgentPubKeyAsync, GetAgentInfoAsync, AddAgentInfoAsync, GetPeerMetaInfoAsync |
| Apps | InstallAppAsync, InstallAppFromBytesAsync, UninstallAppAsync, EnableAppAsync, DisableAppAsync, ListAppsAsync, GetAppInfoAsync |
| DNAs and cells | RegisterDnaAsync, ListDnasAsync, ListCellIdsAsync, GetDnaDefinitionAsync, GetCompatibleCellsAsync, UpdateCoordinatorsAsync, DeleteCloneCellAsync, GraftRecordsAsync |
| Interfaces | AttachAppInterfaceAsync, ListInterfacesAsync, AddAdminInterfacesAsync |
| Security | AuthorizeSigningCredentialsAndGrantZomeCallCapabilityAsync, RevokeZomeCallCapabilityAsync, ListCapabilityGrantsAsync, IssueAppAuthenticationTokenAsync, RevokeAppAuthenticationTokenAsync, GrantDirectSignalCapabilityAsync |
| Diagnostics | GetStorageInfoAsync, DumpStateAsync, DumpFullStateAsync, DumpConductorStateAsync, DumpNetworkStatsAsync, DumpNetworkMetricsAsync, DumpOpTimingsAsync |
The app API
| Area | Methods |
|---|---|
| Zome calls | CallZomeFunctionAsync (many overloads), WaitTillReadyForZomeCallsAsync |
| App info | GetAppInfoAsync, RetrieveAgentPubKeyAndDnaHashAsync |
| Clone cells | CreateCloneCellAsync, EnableCloneCellAsync, DisableCloneCellAsync |
| Membrane proofs | ProvideMemproofsAsync (for apps installed with deferred proofs) |
| Countersigning | GetCountersigningSessionStateAsync, AbandonCountersigningSessionAsync, PublishCountersigningSessionAsync |
| Network | DumpNetworkStatsAsync, DumpNetworkMetricsAsync, GetAppPeerMetaInfoAsync |
| Signals | SendDirectSignalAsync, plus the OnSignalCallBack event |
Events
Every request also raises an event when its response arrives, for example OnAppInstalledCallBack, OnZomeFunctionCallBack and OnSignalCallBack. There are also lifecycle events: OnConnected, OnDisconnected, OnError, OnReadyForZomeCalls, OnHolochainConductorStarting, OnHolochainConductorStarted, OnDataSent and OnDataReceived. The README has the complete list.
Shutting down
await client.DisconnectAsync(); await admin.ShutdownHoloNETAsync(); // disconnects and stops the conductor HoloNET started (if AutoShutdownHolochainConductor)
Threading and sync calls
- Thread safety. Request ids are allocated atomically, so one client can be used from several threads.
- Sync calls inside events. The sync wrappers (
CallZomeFunction,InstallApp, ...) are safe to call from inside HoloNET's own event handlers: HoloNET detects this and avoids deadlocking. - UI apps. HoloNET's receive loop runs off the UI thread. Marshal back to the UI thread yourself in WPF, WinForms or Unity.
Unity
Use the netstandard2.1 build from the same NuGet packages. The HoloUnity notes are in the main README.