Skip to Content
๐ŸŒ Web3๐ŸงŠ IPFS

๐ŸงŠ IPFS

IPFS (InterPlanetary File System) is a decentralized storage and content-addressed network. Files are identified by their content hash (CID), not by a server URL. Itโ€™s widely used in Web3 for NFT metadata, static assets, and data that should be durable and censorship-resistant.


๐ŸŽฏ Why IPFS in Web3

  • Content addressing โ€” Same content โ†’ same CID; no broken links when hosts change
  • Decentralized โ€” No single point of failure; anyone can pin and serve content
  • NFT metadata โ€” ERC721 and Metaplex often point tokenURI / metadata to IPFS
  • dApp assets โ€” Frontend assets or data can be published on IPFS

๐Ÿ“š Core Concepts

TermDescription
CIDContent Identifier โ€” hash of the content (e.g. QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco)
PinStore a copy of the content so it stays available; โ€œpinningโ€ = keeping it
GatewayHTTP endpoint that fetches IPFS content by CID (e.g. https://ipfs.io/ipfs/<CID>)
IPFS nodeClient that can add, get, and pin content on the network

๐Ÿ› ๏ธ Using IPFS

Public gateways (read-only)

You can resolve CIDs via public HTTP gateways:

Example: https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco

Pinning services (upload & pin)

To add and pin content so it stays on the network, use a pinning service or run your own node:


๐Ÿ“ Code: Upload and get CID (Node.js)

Using the official IPFS HTTP clientย  or a pinning API:

// Example: Pinata API (replace with your key and secret) const FormData = require("form-data"); const fs = require("fs"); const fetch = require("node-fetch"); async function uploadToPinata(filePath) { const form = new FormData(); form.append("file", fs.createReadStream(filePath)); const res = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", { method: "POST", headers: { Authorization: `Bearer ${process.env.PINATA_JWT}`, ...form.getHeaders(), }, body: form, }); const data = await res.json(); return data.IpfsHash; // CID } // Usage const cid = await uploadToPinata("./metadata.json"); console.log("CID:", cid); console.log("URL:", `https://ipfs.io/ipfs/${cid}`);

๐Ÿ“ NFT metadata on IPFS

A typical ERC721ย  or Metaplexย  metadata JSON is hosted on IPFS; the contract stores the URI (e.g. ipfs://Qm... or https://ipfs.io/ipfs/Qm...).

Example metadata.json:

{ "name": "My NFT", "description": "Description", "image": "ipfs://QmYourImageCID", "attributes": [ { "trait_type": "Background", "value": "Blue" } ] }

Upload this file to IPFS, then set your contractโ€™s tokenURI to ipfs://<CID> or an HTTP gateway URL.


๐Ÿ”— Resources

Last updated on