A gym tool Holochain Gym Concepts Developers What's next Glossary of Terms Toggle darkmode Give us Feedback!

Basic: Attaching Links

Check-In

So, if you arrived at this point, you might be thinking: "oh okey, I'm beginning to get this! Where should I go next as I'm learning this?"

If this is the case, we'd love for you to join our developer community! Click here. It's the best place to collaborate and learn from each other.

A good way to think about the public DHT holochain data is like a graph: entries are nodes, and links are the edges that connect the entries.

A link has 3 basic properties:

  • A base entry
  • A target entry
  • A tag with arbitrary content

Try it!

To get a better sense of links, try creating a link between two entries:

  1. Create an entry with some content with the create_entry function.
  2. Create a different entry with the same function (remember, if you create an entry with the same content, it won't be a different entry).
  3. Switch to the create_link function.
  4. Click one of the entries from the graph. Copy the "Entry Hash" you see in "Entry Detail" and paste it in the base field.
  5. Click on the other entry, and copy its hash to the target field.
  6. If you want, input some example tag.
  7. Click execute!

Now you should see the two entries linked together.

Great! Now you might be thinking: what do we do with links? Links are useful to attach metadata to entries, without having to change its content (and if we don't change the content, the hash doesn't change either).

Here we have some posts created, with a link from the author public key to all the posts they have created.

Try creating some posts and see how the entries behave, and try to do a get_links with the public key of the author to get the links to all the posts that that agent has created. You can get the public key of the author by clicking on the Agent entry and copying the hash of that entry. All agents create an initial Agent entry when they join the network, in order to be identified by other peers in that DHT.

  1. Go to the developer-exercises.
  2. Enter the nix-shell: nix-shell. you should run this in the folder containing the default.nix file. starting the nix-shell for the very first time might take a long time, somewhere between 20 to 80 minutes, after that it will take just a few seconds.
  3. Implement the functions create_post and get_posts_for_agent.
  4. Compile and test your code: cd tests && npm install && npm test.
  5. Don't stop until the test runs green.