ProtoSchool
Interactive tutorials on decentralized web protocols
Basics | Lesson 2 of 3

Create a new node that's linked to an old one

Useful concepts

CID - Content Identifier. An unique address for a block of data in IPFS that is derived from its content.

DAG - Directed Acyclic Graph. Blocks in IPFS form a graph as they can point to other blocks by their CID. These links can only point one direction (directed) and across the whole graph there are no loops or cycles (acyclic).

One important feature of Directed Acyclic Graphs (DAGs) is the ability to link them together.

The way you express links in the IPFS DAG store is with the CID of another node.

For example, one node might have a link called foo pointed to another CID instance previously saved as barCid, like so:

{
  foo: barCid
}

When we give a field a name and make its value a link to a CID, as shown above, we call this a named link.

We can add named links to IPFS in the same way we add any other data:

await ipfs.dag.put({ foo: barCid })

Try it!

Create a named link called bar that points to the node we created in the first lesson. Put it into IPFS and return its CID.

The editor is pre-populated with the code to create the node we're linking to.

View SolutionReplace with SolutionClear Default Code
Update the code to complete the challenge. Click Submit to check your answer.