Lighthouse
  • 👋Introduction
  • Quick Start
  • How To
    • 🔑Create an API Key
    • 🔼Upload Data
      • 📁File
      • 🔤Text/JSON
      • 🔀Buffer
    • 🔒Upload Encrypted Data
      • 📁File
      • 🔤Text/JSON
      • 🔐Encryption Authentication
        • 📝Method 1: Signed Message
        • ⚕️Method 2: JWT
        • 📲Method 3: Passkey
    • Encryption Features
      • 👯Share File
      • ❌Revoke Access
      • 🔑Check Access Conditions
      • 🚪Token Gating
      • Chains Supported
      • 📃Access Control Conditions
      • 🔓Decrypt File
        • 🌐Browser Decrypt File
        • 💻NodeJS Decrypt File
      • 🚪Access control with zkTLS
      • 👬Account Delegation Tutorial
    • 📂List Files
    • 💁File Info
    • 💰Get Balance
    • 🔁Retrieve File
    • 💾Check for Filecoin Deals
    • 🔄IPNS - Handle Mutable Data
    • 📦Migrate Files
    • 📌Pin CID
    • 💸Pay per use
    • Resize Image
    • 💻Use CLI Tools
  • zkTLS
  • 🤝Account Delegation
  • 💾Filecoin First
    • Usage
    • 💰Pay Per Deal
  • Tutorials
    • 💸Pay to View Application
    • Use Python SDK
    • 📝Update Content with Lighthouse IPNS
    • 📹Add Video Player in UI
    • ✅Document Verification with PoDSI
    • 🎨Minting NFTs on EVM Chains
    • 🪙Minting NFTs on Solana
    • 👩‍💻Programmable Storage with Lighthouse SDK and Filecoin
    • 🔐Secure File Sharing
    • Upload Encrypted Files
    • 📄Token Gating and Custom Contract
    • 🔑Token Gating NFTs
    • 🏖️Pushing File Metadata Onchain
    • Use Radix Wallet on Lighthouse Filesdapp
  • Concepts
    • Glossary
    • IPFS CID Transition to v1
  • Support
    • 📞Contact
Powered by GitBook
On this page
  • 1. What is IPNS?
  • 2. Basic steps involved

Was this helpful?

Edit on GitHub
  1. How To

IPNS - Handle Mutable Data

Using IPNS to handle mutable data

PreviousCheck for Filecoin DealsNextMigrate Files

Last updated 8 months ago

Was this helpful?

IPNS (InterPlanetary Name System) is a system that allows you to create mutable pointers to data in the IPFS network. In simpler terms, it's like a dynamic address that always points to the latest version of your content. Using the Lighthouse SDK, you can easily create, publish, fetch, and remove IPNS records.

1. What is IPNS?

Think of IPNS as a dynamic domain name for your content on IPFS. While IPFS hashes are static and change when content changes, IPNS provides a static address that can be updated to point to new content.

2. Basic steps involved

  1. Create an IPNS key

  2. Map the IPNS key with a CID

  3. In case of CID change just update the mapping, the IPNS key remains the same

  4. View the file using:

Step 1: Create a New IPNS Key

const keyResponse = await lighthouse.generateKey(apiKey)
/* Sample response
{
  data: {
    "ipnsName": "6cda213e3a534f8388665dee77a26458",
    "ipnsId": "k51qzi5uqu5dm6uvby6428rfpcv1vcba6hxq6vcu52qtfsx3np4536jkr71gnu"
  }
}
*/

Upon successful creation, you will receive an IPNS name and its corresponding ID.

Step 2: Publish an IPFS Hash to IPNS

const pubResponse = await lighthouse.publishRecord(
  "YOUR_IPFS_HASH", // replace with your IPFS hash
  keyResponse.data.ipnsName,
  apiKey
)
/* Sample response
{
  data: {
    "Name": "k51qzi5uqu5dm6uvby6428rfpcv1vcba6hxq6vcu52qtfsx3np4536jkr71gnu",
    "Value": "/ipfs/Qmd5MBBScDUV3Ly8qahXtZFqyRRfYSmUwEcxpYcV4hzKfW"
  }
}
*/

The response will show the IPNS name and the IPFS path it points to.

Step 3: Retrieve All IPNS Keys

const allKeys = await lighthouse.getAllKeys(apiKey)
/* Sample response
{
  data: [
    {
      "ipnsName": "6cda213e3a534f8388665dee77a26458",
      "ipnsId": "k51qzi5uqu5dm6uvby6428rfpcv1vcba6hxq6vcu52qtfsx3np4536jkr71gnu",
      "publicKey": "0xc88c729ef2c18baf1074ea0df537d61a54a8ce7b",
      "cid": "Qmd5MBBScDUV3Ly8qahXtZFqyRRfYSmUwEcxpYcV4hzKfW",
      "lastUpdate": 1684855771773
    }
  ]
}
*/

Step 4: Remove an IPNS Key

const pubResponse = await lighthouse.publishRecord("YOUR_IPFS_HASH",ipns_name,apiKey)

Step 5: Update an IPNS Key

const removeRes = await lighthouse.removeKey(keyResponse.data.ipnsName, apiKey)
/* Sample Response
{
  data: { 
    Keys: [
      {
        "Name": "3090a315e92c495ea36444f2bbaeefaf",
        "Id": "k51qzi5uqu5dm8gfelll8own1epd9osmlig49il5mmphkrcxbnhydkmx101x15"
      }
    ]
  }
}
*/
# Generate Key
curl -H 'Authorization: Bearer API_KEY' 'https://api.lighthouse.storage/api/ipns/generate_key'

# Publish CID
curl -H 'Authorization: Bearer API_KEY' 'https://api.lighthouse.storage/api/ipns/publish_record?cid=<cid>&keyName=<key>'

# Get All Keys
curl -H 'Authorization: Bearer API_KEY' 'https://api.lighthouse.storage/api/ipns/get_ipns_records'

# Remove Key
curl -H 'Authorization: Bearer API_KEY' 'https://api.lighthouse.storage/api/ipns/remove_key?keyName=<keyName>'
lighthouse-web3 ipns --generate-key
#Returns:
#ipnsName: ca9e19dcf8e54e86a4dce40b155ffcad
#ipnsId: k51qzi5uqu5dlk72k0t8c80gg8c4lb9bzd0jsd9xtauso88hfkx9ytgm05caao

lighthouse-web3 ipns --publish --key=ca9e19dcf8e54e86a4dce40b155ffcad --cid=QmWC9AkGa6vSbR4yizoJrFMfmZh4XjZXxvRDknk2LdJffc
#Returns:
#Published:
#Visit: https://gateway.lighthouse.storage/ipns/k51qzi5uqu5dlk72k0t8c80gg8c4lb9bzd0jsd9xtauso88hfkx9ytgm05caao

lighthouse-web3 ipns --list
#Returns:
#List of ipns records:
#  Key:     ca9e19dcf8e54e86a4dce40b155ffcad
#  IPNS ID: k51qzi5uqu5dlk72k0t8c80gg8c4lb9bzd0jsd9xtauso88hfkx9ytgm05caao
#  CID:     QmWC9AkGa6vSbR4yizoJrFMfmZh4XjZXxvRDknk2LdJffc
  
lighthouse-web3 ipns --remove ca9e19dcf8e54e86a4dce40b155ffcad
#Returns:
#Record Removed!!!

🔄
https://gateway.lighthouse.storage/ipns/k51qzi5uqu5dlr99jbwpbli7iqtdd60c8hk0wgrsxyvzu3lhymapd1rn4npdd8/