IPFS Cheatsheet

Important Commands:

  • Initialize IPFS:

    ipfs init
    
  • Show Node Information:

    ipfs id
    
  • Run Daemon in Background:

    ipfs daemon &
    
  • Add File:

    ipfs add <file>
    
  • Add Folder Recursively:

    ipfs add -r <folder>
    
  • Pin a File/Folder (Replicate and Keep Locally):

    ipfs pin add <hash>
    
  • List Pinned Files/Folders:

    ipfs pin ls [<hash>]
    
  • Remove Pin:

    ipfs pin rm <hash>
    
  • Get File/Folder from IPFS:

    ipfs get <hash>
    
  • Find Providers of a Hash:

    ipfs dht findprovs <hash>
    
  • Announce that You Have a Hash:

    ipfs dht provide <hash>
    
  • Check if a Node is Reachable:

    ipfs dht findpeer <peerID>
    
  • Show Addresses Connected to Node:

    ipfs swarm addrs listen
    
  • Manually Connect to Another Node:

    ipfs swarm connect <multiaddr>
    

Configuration for a Public Node:

  1. First Time Config Setup for a Server:

    ipfs init --profile server
    

    Note: This removes local discovery requests.

  2. Setup Circuit Relay V2:

    • Add swarm address in the config:

      "Swarm": [
        "/ip4/0.0.0.0/tcp/4001",
        "/ip4/0.0.0.0/tcp/4004/ws",
        "/ip6/::/tcp/4001",
        "/ip4/0.0.0.0/udp/4001/quic",
        "/ip6/::/udp/4001/quic"
      ]
      
    • Enable Swarm.RelayService and Swarm.RelayClient:

      ipfs config --json Swarm.RelayService.Enabled true
      ipfs config --json Swarm.RelayClient.Enabled true
      
  3. Enable Public Gateway with Nginx:

    server {
        listen 80;
        server_name gateway.maxcoinproject.net;
    
        location / {
            proxy_pass http://localhost:8080;
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            allow all;
        }
    }
    

    Note: Remember to enable the service and get SSL with certbot.

  4. Enable Secure WebSocket with Nginx:

    server {
        listen 80;
        server_name ipfsnode.maxcoinproject.net;
    
        location / {
            proxy_pass http://127.0.0.1:4004;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    

    Note: Remember to enable the service and get SSL with certbot.

  5. Verify Secure WebSocket Connection:

    • IPFS Ping:

      ipfs ping /dns4/ipfsnode2.maxcoinproject.net/tcp/443/wss/p2p/<peerID>
      
    • Swarm Connect:

      ipfs swarm connect /dns4/ipfsnode2.maxcoinproject.net/tcp/443/wss/p2p/<peerID>
      

Sources:

  1. IPFS File Transfer
  2. Libp2p Circuit Relay
  3. Understanding IPFS Circuit Relay
  4. IPFS Experimental Features

Replace <file>, <folder>, <hash>, <peerID> with the appropriate values when using these commands.