Building Holochain Apps: Bridging

As you saw in Building Apps each DNA has a unique hash that spawns a brand new DHT network and creates isolated source chains for each agent. Even when you change the DNA, releasing a new version of the app, it will spawn a brand new DHT network and source chains.

So if every app lives in an entirely separated world how can they talk to each other? This is where bridging comes into play.

A bridge is a connector between two apps (or two versions of the same app, for that matter) that allows synchronous, bidirectional transfer of information between them. It’s important to note that this bridge connects two DNA instances on one machine; therefore, all function calls using this bridge are done from the perspective of the agent, not the apps as a whole.

To use a bridge, right now you need to configure a production Holochain conductor, at least two instances configured, along the lines of the following example setup (in a conductor-config.toml file):

id = "caller-instance"
dna = "caller-dna"
agent = "caller-agent"
type = "simple"
type = "memory"

id = "target-instance"
dna = target-dna"
agent = "target-agent"
type = "simple"
type = "memory"

caller_id = "caller-instance"
callee_id = "target-instance"
handle = "sample-bridge"

Then on the caller DNA you have to initiate the bridge call using hdk::call like this:

    let response = match hdk::call(
        Address::from(PUBLIC_TOKEN.to_string()), // never mind this for now
            "some_param": "some_val",
    ) {
        Ok(json) => serde_json::from_str(&json.to_string()).unwrap(), // converts the return to JSON
        Err(e) => return Err(e)

And the corresponding target / callee DNA on the other end should have a zome called “sample_zome”, with a function as follows:

pub fn handle_sample_function(some_param: String) -> ZomeApiResult<Address> {
    // do something here

define_zome! {
    entries: []

    init: || { Ok(()) }

    validate_agent: |validation_data : EntryValidationData::<AgentId>| {

    functions: [
        sample_function: {
            inputs: |some_param: String|,
            outputs: |result: ZomeApiResult<Address>|,
            handler: handle_sample_function

    traits: {
        hc_public [

Remember that the call will block the execution of the caller DNA until the callee (target) finishes executing the call, so it’s best to mind performance issues when working with bridges. Try to make contextual or incremental calls rather than all-encompassing ones.

Was this helpful?