Playing with IPLD

Initial IPLD support has been released in ipfs v0.4.5, Its been a long time coming and we're so excited to have it out and ready for people to use. Before following along on the rest of this guide, please go ahead and update to at least ipfs 0.4.5.

What is IPLD?

IPLD is a data format for merkle-linked objects. Its purpose is to make it easy to build your own hash linked data structures and move them around with ipfs. IPLD objects are stored and moved around by IPFS encoded with CBOR, but can be written and operated on in JSON or any other schemaless serialization format (though currently only JSON is supported by go-ipfs). An IPLD object looks something like this:

	"hello": "world",
	"foo": {"/": "QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM"},
	"baz": [
		{"/": "QmWg1Ux3cb3xCToGBCmZBNaMvpcFhTEEjb74fruG9uVHja"}

The basic idea is that any valid CBOR object (and subsequently, any valid JSON object since they map 1-to-1) can be an IPLD object. On top of that, theres a special format for inserting merkle-links that is the real meat of IPLD. The strange objects with a key of '/' and a value of an ipfs hash are the links. These links are understood by ipfs and can be used to build path references across objects.

To put the above object into ipfs, save it to a file and use 'ipfs dag put thatfile'. It will spit out a hash, assuming I didn't mess up and change the example after writing this, the hash should be 'zdpuB142C6iQX61bUjnxzYBxBXQXEmafpQHmH1j75WURgKiqh'. You can address paths over this, for example:

[whyrusleeping@source ~]$ echo "bar" | ipfs add # make sure the linked objects are available
added QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM
[whyrusleeping@source ~]$ echo "i'm a cat!" | ipfs add
added QmWg1Ux3cb3xCToGBCmZBNaMvpcFhTEEjb74fruG9uVHja QmWg1Ux3cb3xCToGBCmZBNaMvpcFhTEEjb74fruG9uVHja
[whyrusleeping@source ~]$ ipfs dag put foo.json
[whyrusleeping@source ~]$ export HASH=zdpuB142C6iQX61bUjnxzYBxBXQXEmafpQHmH1j75WURgKiqh
[whyrusleeping@source ~]$ ipfs cat $HASH/foo
[whyrusleeping@source ~]$ ipfs cat $HASH/baz/0
i'm a cat!

You can also view dag objects directly with 'ipfs dag get'

[whyrusleeping@source ~]$ ipfs dag get $HASH
[whyrusleeping@source ~]$ ipfs dag get $HASH/hello
[whyrusleeping@source ~]$ ipfs dag get $HASH/baz