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

Create a node and return a Content Identifier (CID)

Useful concepts

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

In this tutorial we'll be exploring the IPFS DAG API, which lets us store data objects in IPFS. (You can store more exciting things in IPFS, like your favorite cat GIF, but you'd need to use a different API for that.)

You can create a new node by passing a data object into the ipfs.dag.put method, which returns a Content Identifier (CID) for the newly created node.

ipfs.dag.put({ hello: 'world' })

A CID is an address for a block of data in IPFS that is derived from its content. Every time someone puts the same { hello: 'world' } data into IPFS, they'll get back an identical CID to the one you got. If they put in { hell0: 'w0rld' } instead, the CID will be different.

Note: Throughout our lessons we'll be using a code editor like the one below. Enter your solution code within the run function that's pre-populated for you, being sure to return the requested value within that function. (You won't need to update the return run line at the end; that's just there to make the code editor work.)

Try it!

Use ipfs.dag.put to create a node for the data { test: 1 }. Return the CID of your new node.

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