Configuration

Config is an object with helper functions for configuration that is exported from holochain-nodejs and can be imported into your code. The functions can be combined to produce a valid configuration object to instantiate a Conductor instance with.

Import Example

const { Config } = require('@holochain/holochain-nodejs')

Agent

Config.agent(agentName) => object

Takes an agent name and creates a simple configuration object for that agent


Name agentName

Type string

Description An identifying string for this agent


Example

const agentConfig = Config.agent('alice')
console.log(agentConfig)
/*
{
    name: 'alice'
}
*/

DNA

Config.dna(dnaPath, [dnaName]) => object

Takes a path to a valid DNA package, and optionally a name and creates a simple configuration object for that DNA


Name dnaPath

Type string

Description The path to a .dna.json file containing a valid DNA configuration


Name dnaName Optional

Type string

Description The path to a .dna.json file containing a valid DNA configuration

Default The same as the given dnaPath


Example

const dnaConfig = Config.dna('path/to/your.dna.json')
console.log(dnaConfig)
/*
{
    path: 'path/to/your.dna.json',
    name: 'path/to/your.dna.json'
}
*/

Instances

Config.instance(agentConfig, dnaConfig, [name]) => object

Takes an agent config object and a dna confid object, and optionally a unique name, and returns a full configuration object for a DNA instance.


Name agentConfig

Type object

Description A config object with a name property, as produced by Config.agent


Name dnaConfig

Type object

Description A config object with a name and path property, as produced by Config.dna


Name name Optional

Type string

Description The name acts like the instance ID, and in fact will be used as such when calling Zome functions

Default The same as the name property of the given agentConfig (agentConfig.name)


Example

const agentConfig = Config.agent('alice')
const dnaConfig = Config.dna('path/to/your.dna.json')
const instanceConfig = Config.instance(agentConfig, dnaConfig)
console.log(dnaConfig)
/*
{
    agent: {
        name: 'alice'
    },
    dna: {
        path: 'path/to/your.dna.json',
        name: 'path/to/your.dna.json'
    },
    name: 'alice'
}
*/

Full Conductor Configuration

Config.conductor(instancesArray, [conductorOptions]) => object

Consumes an array of configured instances and produces an object which is a fully valid Conductor configuration. It can be passed into the Conductor constructor, which is covered in the next articles.

This function is mostly useful in conjunction with manually instantiating a Conductor.


Name instancesArray

Type array

Description Pass in an array of instance configuration objects generated by Config.instance to have them within the final configuration to be instantiated by the Conductor


Name conductorOptions Optional

Type object

Description conductorOptions.debugLog boolean Enables debug logging. The logger produces nice, colorful output of the internal workings of Holochain.

Default { debugLog: false }


Example

const agentConfig = Config.agent('alice')
const dnaConfig = Config.dna('path/to/your.dna.json')
const instanceConfig = Config.instance(agentConfig, dnaConfig)
const conductorConfig = Config.conductor([instanceConfig])

Example With conductorOptions

const agentConfig = Config.agent('alice')
const dnaConfig = Config.dna('path/to/your.dna.json')
const instanceConfig = Config.instance(agentConfig, dnaConfig)
const conductorConfig = Config.conductor([instanceConfig], { debugLog: true })

Multiple Instances Example

const { Config } = require('@holochain/holochain-nodejs')

// specify two agents...
const aliceName = "alice"
const bobName = "bob"
const agentAlice = Config.agent(aliceName)
const agentBob = Config.agent(bobName)
// ...and one DNA...
const dnaPath = "path/to/happ.dna.json"
const dna = Config.dna(dnaPath)
// ...then make instances out of them...
const instanceAlice = Config.instance(agentAlice, dna)
const instanceBob = Config.instance(agentBob, dna)
// ...and finally throw them all together
const config = Config.conductor([instanceAlice, instanceBob])

suggest an edit