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.
What is a link?
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 link type (a number that identifies the type of the link)
- A tag with arbitrary content
Try it!
To get a better sense of links, try creating a link between two entries:
- Create an entry with some content with the
create_entry
function. - 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).
- Switch to the
create_link
function. - Click one of the entries from the graph. Copy the "Entry Hash" you see in "Entry Detail" and paste it in the
base
field. - Click on the other entry, and copy its hash to the
target
field. - If you want, input some example tag.
- 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.
- Go to the
developer-exercises
. - Enter the nix-shell:
nix-shell
. you should run this in the folder containing the default.nix file. - Implement the functions
create_post
andget_posts_for_agent
. - Compile and test your code:
cd tests && npm test
. - Don't stop until the test runs green.