Skip to content

Description

In this tutorial we will be learning about IPLD and CID's which are used in IPFS. We will be generating CID's manually using three different tools and validating that they all produce the same output.

This is a requirement for my IPLD User Model

Question Engine Memes are CID's

The Question Engine - QE application I am working on has RBAC. This means that some data shared by someone to someone else is not supposed to be uploaded to the public internet. But if that data was uploaded to the internet it would use the same CID. This also allows data that is shared privately to later be share publicly and not have to update any private references to it.

Learn more about CID's

Goals of This Tutorial

  • Install Kubo the Go IPFS implementation
  • Managing Raw Files in IPFS
    • Add files to IPFS using Kugo and get CID
    • Use Javascript to produce CID + CAR of raw image file
    • Use Python to produce CID + CAR using raw image file
  • DAG-JSON and IPFS
    • Use Javascript to produce CID of DAG-JSON
    • Use Python to produce CID of DAG-JSON
  • Managing Folders in IPFS

Install Kugo

Just follow this -> Kubo | IPFS Docs

Add files to IPFS using Kugo and get CID

mkdir test
cd test
cat "helloworld" > helloworld
ipfs add --cid-version 0 helloworld
# added QmUZ6YmQSmu9CV7KAT2tj6UEeGacD8MvB7wXKEWKG584Gn helloworld
ipfs cat QmUZ6YmQSmu9CV7KAT2tj6UEeGacD8MvB7wXKEWKG584Gn

ipfs add --cid-version 1 helloworld
# added bafybeic4kzhlnhbbxw76qpodl7w7rwxyj7gyv4sybdz5f6wfaf5nfezew4 helloworld
ipfs cat bafybeic4kzhlnhbbxw76qpodl7w7rwxyj7gyv4sybdz5f6wfaf5nfezew4

Use Javascript to produce CID + CAR of DAG-JSON

TODO

JavaScript Libraries

# Optional: Create npm package
npm init -y

npm install multiformats
npm install @ipld/dag-json
npm install ajv
npm install ajv-formats
npm install @ipld/dag-pb # for CIDv0

Python Libraries

# Optional: Setup python virtual environment
python3 -m pip install virtualenv
python3 -m venv env
source env/bin/activate

python3 -m pip install multiformats[full]
python3 -m pip install dag-json
python3 -m pip install jsonschema
python3 -m pip install jsonschema[format]

Managing Raw Files in IPFS

DAG-JSON and IPFS

Sources