#S:EXTERNAL=rust=hello_world.rs #S:MODE=test,INCLUDE #S:EXTERNAL=javascript=hello_world.js=test
The goal of this tutorial is to add an entry in Alice's instance and then retrieve that same entry in Bob's instance.
So far the only entry you have had has been private. But this isn't that useful if you want your users to be able to share entries on the same network.
Open up your zomes/hello/code/src/lib.rs
file.
Change the entry sharing to Sharing::Public
:
Previously you made a test where Alice made a few zome calls and verified the results. Now, to test that the entries can be shared between agents on the same DNA, you can use Bob in your tests to interact with Alice.
Open up your test/index.js
file and add/update the following lines:
Add bob
to the scenario:
Make the retrieve_person
call with the result from create_person
:
#S:HIDE,SKIP
Check that the result was Ok:
Check that the result does indeed match the person entry that Alice created:
#S:HIDE
Your test should look like this:
#S:CHECK=javascript=test
Enter the nix-shell if you don't have it open already:
Now run the test and make sure it passes:
Now it would be cool to see this happen for real outside of a test. Up till now you have only used hc run
to run a single instance of a node. However, in order to have two separate instances communicate on one machine, we need to run holochain
directly and pass it a config file.
Note
hc
andholochain
are both conductors that host your apps on your users' machines.hc run
is for testing and development, andholochain
is for end-users. It can host multiple instances of multiple DNAs for multiple users. Normally Alice and Bob would be running instances of your app in their own conductors on their own machines. But for the purposes of this tutorial, it'll be a lot more convenient to try this on one machine, so you don't have to worry about network setup.
Before you can create the config file, you will need to generate some keys for your agents.
Use hc keygen
in your nix-shell to generate a key for each agent:
This will output something similar to the following:
Take note of the Public address
; you will need it later.
Copy the newly generated keystore to your working folder (replace the path with the one in the Keystore written to:
line from the output of the previous command):
Now run hc keygen
again but copy the key store to agent2.key:
Create a new file in the root directory of your project called conductor-config.toml
.
Add an agent with ID test_agent1
and name it Agent 1
:
Use the public address and keystore from hc keygen
that you made for agent 1 before here:
Add an agent with ID test_agent2
and name it Agent 2
:
Use the public address and keystore from hc keygen
that you made for agent 2 before here:
Package your DNA and take note of its hash:
You will see something similar to this:
Add the DNA to your config file with ID hello
and the hash you just saw above:
Connect agent 1 to the hello
DNA to create an instance for Alice:
Add the Bob instance with the same hello
dna:
Setup the WebSocket interface on socket 3041
:
Add your instances to this interface so you can call their zome functions:
Note
Again, in real life Alice and Bob would each have their own conductor, so they wouldn't be listening on the same WebSocket interface.
Before you can use two agents, you need a way for the UI to specify which instance the user wants to use. You can do this by setting the instance ID in the zome call. You can think of an instance as a running version of a DNA, in the same way that a variable is an instance of a struct.
Open the gui/index.html
file.
Add a text box for your users to set the agent ID:
Open the gui/index.js
and do the following for every callZome
call:
Now the fun part, where you get to play with what you just wrote.
Open up three terminal windows and enter the nix-shell in each one:
Go to the root folder of your app:
Start by running the conductor. It's a bit different this time; instead of hc run
you will use holochain
directly:
Go to the root folder of your GUI:
Run a GUI on port 8000
:
Go to the root folder of your GUI:
Run a GUI on port 8001
:
Open two tabs.
Go to 0.0.0.0:8000
. Enter Alice
into the Enter your instance ID
text box.
Go to 0.0.0.0:8001
. Enter Bob
into the Enter your instance ID
text box.
Create a person entry with your name:
Copy the address from the Alice tab and retrieve the person entry:
Hooray! Alice and Bob are now able to find each other's information on the DHT