Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
node_modules
# Dependency folder
node_modules/
# logs
package-lock.json
# Operating system files
.DS_Store
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
# Introduction
[![](https://img.shields.io/badge/license-MIT-green)](https://opensource.org/licenses/MIT)
[![](https://img.shields.io/badge/project-machu----picchu-brightgreen)](https://github.com/Machu-Pichu/general.git)
[![](https://img.shields.io/badge/usage-tutorial-lightgreen)](https://github.com/Machu-Pichu/general.git)

*(Written in June 2021)*

This is a fork of the repository of [Vaibhav Saini](https://github.com/vasa-develop/ultimate-ipfs-series)
The contribution is to update the code at the latest versions of the npm packages as of June 2021. The snippets have all been executed and are working. Only the first 4 articles have been updated. The last 2 articles require a Medium account to read that I don't have.

The licensing status of the original code of Vasa is unknown. But as long as all the code that I made here are new and inspired also by the original example of the [IPFS documentation site](https://github.com/ipfs/js-ipfs), the license of this code is MIT.
## To use the code snippets
To use the code snippets, you need to install NodeJS. The setup instructions use the console utility (`Terminal.app`) from MacOS. Excepted for `brew`, the setup instructions are the same if you use Linux Ubuntu.

* Install [Brew](https://brew.sh/)
* Install nodeJS via brew: `brew install [email protected]` (this version of nodeJS is the last long term stable support)
* Install `wget` via brew: `brew install wget` (we'll need `wget` to retrieve the homepage of Vasa in the post _Understanding IPFS in Depth(1/6): A Beginner to Advanced Guide_)

Under Windows, it is strongly recommended to run a [VirtualBox](https://www.virtualbox.org/wiki/Downloads) for Windows and install a Ubuntu Virtual Machine inside it. Here is a YouTube video of 4 minutes, that can guide you through this double installation process: https://youtu.be/8mns5yqMfZk.
## Overview of changes (for the Pull Request)
* all `package.json` have the latest versions of IPFS packages, as of June 2021
* the APIs of IPFS have changed, no more callback with `err` code, so we use liberally `try-catch` coding
* the `package.json` refer to the latest `npm` packages, as of June 2021
* each exercise has a modified readme
# ultimate-ipfs-series
An Ultimate tutorial series to learn about IPFS, IPLD, Multiformats, Libp2p and Filecoin

This repository is a consolidated list of resources you can follow to learn about IPFS.
To keep the things simple and managable, all the resources are grouped and presented in form of a series of blog posts(6 posts):
- [**Understanding IPFS in Depth(1/6): A Beginner to Advanced Guide**](https://hackernoon.com/understanding-ipfs-in-depth-1-5-a-beginner-to-advanced-guide-e937675a8c8a): In this part, we will try to understand What IPFS is, Why do we need it and What we can do with it. We will cover all the underlying components of IPFS in brief(which will be explained in depth in further parts) and see how they work together. If you want a short summary and don’t want to understand what’s happening “under the hood”, then this part is for you 😊
- [**Understanding IPFS in Depth(2/6): What is InterPlanetary Linked Data(IPLD)?**](https://hackernoon.com/understanding-ipfs-in-depth-2-6-what-is-interplanetary-linked-data-ipld-c8c01551517b): In this part, we will dive into the data model of the content-addressable web. We will explore the details and specs of IPLD and play with it to get more familiar with it.
- [**Understanding IPFS in Depth(3/6): What is InterPlanetary Naming System(IPNS)?**](https://hackernoon.com/understanding-ipfs-in-depth-3-6-what-is-interplanetary-naming-system-ipns-9aca71e4c13b): In this part, we will dive into the naming System of the distributed web. We will discuss it’s working, specs and play with it. We will also compare it to today’s naming system, aka the DNS. We will create a list of pros and cons of IPNS vs DNS.
- [**Understanding IPFS in Depth(4/6): What is MultiFormats?**](https://hackernoon.com/understanding-ipfs-in-depth-4-6-what-is-multiformats-cf25eef83966): In this part, we will talk about Why we need Multiformat, How it works and What you as a user/developer can do with it?
- [**Understanding IPFS in Depth(5/6): What is Libp2p?**](https://medium.com/@vaibhavsaini_67863/understanding-ipfs-in-depth-5-6-what-is-libp2p-f8bf7724d452): In this part, we will study the networking Layer of IPFS and what it contributes to the awesomeness of IPFS. We will go through it’s working, specs and play around with it to understand it more clearly.
- [**Understanding IPFS in Depth(6/6): What is Filecoin?**](https://medium.com/swlh/ultimate-guide-to-filecoin-breaking-down-filecoin-whitepaper-economics-9212541a5895): In this part, we discuss the incentivization layer of IPFS, filecoin. We discuss it’s whitepaper and it’s implementation specs including DSN(Distributed Storage Network), Proof-of-replication, Proof of Storage, Data storage and retrieval markets and Smart contract implementation on Filecoin protocol. We also discuss some flaws in filecoin protocol which are not mentioned in the whitepaper and suggest some improvements in filecoin protocol.
- [**Understanding IPFS in Depth(2/6): What is InterPlanetary Linked Data(IPLD)?**](https://hackernoon.com/understanding-ipfs-in-depth-2-6-what-is-interplanetary-linked-data-ipld-c8c01551517b) In this part, we will dive into the data model of the content-addressable web. We will explore the details and specs of IPLD and play with it to get more familiar with it.
- [**Understanding IPFS in Depth(3/6): What is InterPlanetary Naming System(IPNS)?**](https://hackernoon.com/understanding-ipfs-in-depth-3-6-what-is-interplanetary-naming-system-ipns-9aca71e4c13b) In this part, we will dive into the Naming System of the distributed web. We will discuss it’s working, specs and play with it. We will also compare it to today’s naming system, aka the DNS. We will create a list of pros and cons of IPNS vs DNS.
- [**Understanding IPFS in Depth(4/6): What is MultiFormats?**](https://hackernoon.com/understanding-ipfs-in-depth-4-6-what-is-multiformats-cf25eef83966) In this part, we will talk about Why we need Multiformat, How it works and What you as a user/developer can do with it?
- [**Understanding IPFS in Depth(5/6): What is Libp2p?**](https://medium.com/@vaibhavsaini_67863/understanding-ipfs-in-depth-5-6-what-is-libp2p-f8bf7724d452) In this part, we will study the networking Layer of IPFS and what it contributes to the awesomeness of IPFS. We will go through it’s working, specs and play around with it to understand it more clearly.
- [**Understanding IPFS in Depth(6/6): What is Filecoin?**](https://medium.com/swlh/ultimate-guide-to-filecoin-breaking-down-filecoin-whitepaper-economics-9212541a5895) In this part, we discuss the incentivization layer of IPFS, filecoin. We discuss it’s whitepaper and it’s implementation specs including DSN(Distributed Storage Network), Proof-of-replication, Proof of Storage, Data storage and retrieval markets and Smart contract implementation on Filecoin protocol. We also discuss some flaws in filecoin protocol which are not mentioned in the whitepaper and suggest some improvements in filecoin protocol.

## More reading
Once you get familiarized with IPFS after running the exercises of this repository, you may want to try [this complete free course from ProtoSchool](https://proto.school/tutorials?course=ipfs). It's from Protocol Labs, the team who created IPFS.

Binary file added cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion ipld-blogs/.gitignore

This file was deleted.

21 changes: 16 additions & 5 deletions ipld-blogs/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# Understanding IPLD(InterPlanetary Linked Data)
This tutorial is a part of Medium Article Series ***"Understanding IPFS in Depth"*** authored by [**vasa**](https://vaibhavsaini.com).

You can read the full article here: [*Understanding IPFS in Depth(2/6): What is InterPlanetary Linked Data(IPLD)?*](https://medium.com/towardsblockchain/understanding-ipfs-in-depth-2-6-what-is-interplanetary-linked-data-ipld-c8c01551517b).
You can read the full article here: [*Understanding IPFS in Depth(2/6): What is InterPlanetary Linked Data(IPLD)?*](https://medium.com/towardsblockchain/understanding-ipfs-in-depth-2-6-what-is-interplanetary-linked-data-ipld-c8c01551517b)

## Running this tutorial
Beware that **the code of the Medium post is obsolete**. Use the code here instead. It runs with
* [email protected]
* [email protected]
+ [email protected]
## Run this tutorial
* `cd` to this folder
* Run `npm install` to install the dependencies.
* Run `node tut1.js` to creating an IPLD format node.
* Run `node tut2.js` to create 2 nodes and linking second node to first node using named link.
* Run `node tut3,js` to fetch the value of a node using links.
* Run `node ipld_node.js` to creating an IPLD format node.
* Run `node named_link.js` to create 2 nodes and linking second node to first node using named link.
* Run `node nested_data.js` to fetch the value of a node using links.
* Run `node ipld-blogs.js` to run the medium type publication tutorial.

## More reading
You may want to try [these exercises from ProtoSchool](https://proto.school/basics).
They are about the same topics as the first 3 exercises, but explained differently.

This [ProtoSchool link to a decentralised blog](https://proto.school/blog) is the same topic as the 4th exercise.
50 changes: 29 additions & 21 deletions ipld-blogs/ipld_node.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
//Initiate ipfs and CID instance
/*
* tutorial IPLD by Vaibhav Saini, updated by Vu Tien Khang (June 2021)
* create an IPLD node and print its CID
*/
//Import ipfs and CID instance
const ipfsClient = require('ipfs-http-client');
const CID = require('cids');

//Connecting ipfs http client instance to local IPFS peer.
const ipfs = new ipfsClient({ host: 'localhost', port: '5001', protocol: 'http' });
async function main() {
/*
* Connect ipfs instance to infura node. You can also use your local node (non secure http) by calling
* const ipfs = await ipfsClient.create({host: 'localhost', port: '5001', protocol: 'http'});
* [obsolete tutorial code] const ipfs = new ipfsClient({ host: 'ipfs.infura.io', port: '5001', protocol: 'https' });
*/
// const ipfs = await ipfsClient.create({host: 'localhost', port: '5001', protocol: 'http'});
const ipfs = await ipfsClient.create({ host: 'ipfs.infura.io', port: '5001', protocol: 'https' });

/*
Creating an IPLD format node:
ipfs.dag.put(dagNode, [options], [callback])
For more information see:
https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/DAG.md#ipfsdagputdagnode-options-callback
*/

ipfs.dag.put({ name: "vasa" }, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid) => {
if (err) {
console.log("ERR\n", err);
}

//featching multihash buffer from cid object.
/*
* Create an IPLD format node: ipfs.dag.put(dagNode, [options])
* For more information see:
* https://github.com/ipfs-inactive/interface-js-ipfs-core/blob/master/SPEC/DAG.md#ipfsdagputdagnode-options
*/
const cid = await ipfs.dag.put({name: "vasa"}, { format: 'dag-cbor', hashAlg: 'sha2-256' });

//fetch multihash buffer from cid object.
const multihash = cid.multihash;

//passing multihash buffer to CID object to convert multihash to a readable format
//pass a multihash buffer to CID object to convert multihash to a readable format
const cids = new CID(1, 'dag-cbor', multihash);

//Print out the cid in a readable format
console.log('CID =', cids.toBaseEncodedString('base58btc'));
//bafyreiekjzonwkqd7vcfescxlhvuyn6atdvgevirauupbkncpyebllcuh4 (in base32 by default, CID v1)
//zdpuAujL3noEMamveLPQWJPY6CYZHhHoskYQaZBvRbAfVwR8S (value given in tutorial, CID v0)
};

//Printing out the cid in a readable format
console.log(cids.toBaseEncodedString());
//bafyreiekjzonwkqd7vcfescxlhvuyn6atdvgevirauupbkncpyebllcuh4
});
main();
34 changes: 18 additions & 16 deletions ipld-blogs/named_link.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
//Initiate ipfs and CID instance
/*
* tutorial IPLD by Vaibhav Saini, updated by Vu Tien Khang (June 2021)
* create 2 IPLD nodes, with the 2nd referring to the first,
* note that both nodes have the same CID
*/
//Import ipfs and CID instance
const ipfsClient = require('ipfs-http-client');
const CID = require('cids');

//Connecting ipfs http client instance to local IPFS peer.
const ipfs = new ipfsClient({ host: 'localhost', port: '5001', protocol: 'http' });

/*
Creating an IPLD format node:
ipfs.dag.put(dagNode, [options], [callback])
For more information see:
https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/DAG.md#ipfsdagputdagnode-options-callback
*/
async function linkNodes() {
//Connect ipfs http client instance to local IPFS peer.
const ipfs = await ipfsClient.create({ host: 'ipfs.infura.io', port: '5001', protocol: 'https' });

// Create an IPLD format node: ipfs.dag.put(dagNode, [options])
let vasa = await ipfs.dag.put({ name: 'vasa' });

//Linking secondNode to vasa using named link.
//Link secondNode to vasa using named link.
let secondNode = await ipfs.dag.put({ linkToVasa: vasa });

//featching multihash buffer from cid object.
//fetch multihash buffer from cid object.
const multihash = secondNode.multihash;

//passing multihash buffer to CID object to convert multihash to a readable format
//pass multihash buffer to CID object to convert multihash to a readable format
const cids = new CID(1, 'dag-cbor', multihash);

//Printing out the cid in a readable format
console.log(cids.toBaseEncodedString());
//print out the cid in a readable format, base32 and base 58btc
console.log('CID base32 V1 =', cids.toBaseEncodedString());
//bafyreigwftw565twi6kw3azu7hgz2lxoev3um6cjpgbn6lunqp6f3ewpve
console.log('CID base58btc V1 =', cids.toBaseEncodedString('base58btc'));
//zdpuAujL3noEMamveLPQWJPY6CYZHhHoskYQaZBvRbAfVwR8S
}

linkNodes();
linkNodes();
51 changes: 30 additions & 21 deletions ipld-blogs/nested_data.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
//Initiate ipfs and CID instance
/*
* tutorial IPLD by Vaibhav Saini, updated by Vu Tien Khang (June 2021)
* create 2 IPLD nodes, with the 2nd referring to the first,
* traverse the link to fetch the value in first node
*/
//Import ipfs and CID instance
const ipfsClient = require('ipfs-http-client');
const CID = require('cids');

//Connecting ipfs http client instance to local IPFS peer.
const ipfs = new ipfsClient({ host: 'localhost', port: '5001', protocol: 'http' });
async function createAndFetchNodes() {
//Connect ipfs http client instance to local IPFS peer.
const ipfs = await ipfsClient.create({ host: 'ipfs.infura.io', port: '5001', protocol: 'https' });

function errOrLog(err, result) {
if (err) {
console.error('error: ' + err)
} else {
console.log(result)
}
}

async function createAndFeatchNodes() {
let vasa = await ipfs.dag.put({ name: 'vasa' });
// Create an IPLD format node: ipfs.dag.put(dagNode, [options])
const vasa = await ipfs.dag.put({ name: 'vasa' });

//Linking secondNode to vasa using named link.
let secondNode = await ipfs.dag.put({
// Link 2nd node to vasa using named link
const secondNode = await ipfs.dag.put({
publication: {
authors: {
authorName: vasa
}
}
});

//featching multihash buffer from cid object.
// Fetch multihash buffer from cid object.
const multihash = secondNode.multihash;

//passing multihash buffer to CID object to convert multihash to a readable format
// Pass multihash buffer to CID object to convert multihash to a readable format
const cids = new CID(1, 'dag-cbor', multihash);

//Featching the value using links
ipfs.dag.get(cids.toBaseEncodedString() + '/publication/authors/authorName/name', errOrLog);
/* prints { value: 'vasa', remainderPath: '' } */
// Fetch the value using links, using various formats, as in
// https://github.com/ipfs-inactive/interface-js-ipfs-core/blob/master/SPEC/DAG.md#ipfsdaggetcid-path-options
const cidAlone = await ipfs.dag.get(cids);
console.log(' 0. cid instance alone =', cidAlone);
const cidPath = await ipfs.dag.get(cids, '/publication/authors/authorName/name');
console.log(' 1. cid instance & distinct path =', cidPath);
const cidString = await ipfs.dag.get(cids.toBaseEncodedString(), '/publication/authors/authorName/name');
console.log(' 2. cid as string & distinct path =', cidString);
const cidStringPath = cids.toBaseEncodedString()+'/publication/authors/authorName/name';
console.log(' cidStringPath =', cidStringPath);
const nodeValue = await ipfs.dag.get (cidStringPath);
console.log(' 3. cid as string cat\'ed with path =', nodeValue);
console.log(' -> only the last call traverses the path');
}
createAndFeatchNodes();

createAndFetchNodes();
Loading