A Comprehensive Guide to Publishing and Updating Content with Lighthouse IPNS
Lighthouse IPNS (InterPlanetary Naming System) is a valuable tool that enables the creation of mutable pointers to content-addressed data in the IPFS (InterPlanetary File System) network. While IPFS ensures content immutability by generating unique CIDs for each piece of data, IPNS allows for regular updates to the content while retaining a consistent address. In this tutorial, we will explore two methods to publish and update content with Lighthouse IPNS: using the CLI (Command Line Interface) and Node.js. By the end of this guide, you will be able to effectively publish and manage IPNS records, making your content easily accessible and updatable.
Before we get started, ensure you have the following:
In IPFS, content is typically addressed using CIDs, making it immutable. However, there are scenarios where content needs to be regularly updated, such as publishing a frequently changing website. IPNS addresses this challenge by creating mutable pointers to CIDs, known as IPNS names. These names act as links that can be updated over time while maintaining the verifiability of content addressing. Essentially, IPNS enables the sharing of a single address that can be updated to point to the new CID whenever content changes.
How IPNS Works:
Go on https://files.lighthouse.storage/ and Click on Login
Select any of the login method and perform verification steps
Click on API Key on the left side panel on the dashboard.
Insert name for your API
Copy the API Key
Step 1: Generate an IPNS key using the Lighthouse CLI:
lighthouse-web3 ipns --generate-key
This command will return an IPNS name and ID, which we will use later to publish the content.
Step 2: Make a test file, text.txt:
echo "Hello World" >> text.txt
Step 3: Publish this file to the IPFS using lighthouse upload:
lighthouse-web3 upload ./text.txt
Step 4: Publish the content using the generated IPNS key and the CID of the data you want to publish:
lighthouse-web3 ipns --publish --key=8f4f116282a24cec99bcad73a317a3f4 --cid=QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u
You will receive a link that can be used to access the published content. This link will remain valid even if the content's IPFS hash changes.
Upload another file text2.txt:
echo "Hello World2" >> text2.txt
Publish this file to the IPFS using lighthouse upload:
lighthouse-web3 upload ./text2.txt
Update the content using the generated IPNS key and the CID of the data you want to publish:
lighthouse-web3 ipns --publish --key=8f4f116282a24cec99bcad73a317a3f4 --cid=QmanCeGkwsaCUHaNT24ndriYTYSwZuAy4JDifdYZpHdmRa
You will receive a link that can be used to access the published content. This link will remain valid even if the content's IPFS hash changes.
List all IPNS records associated with your Lighthouse account:
lighthouse-web3 ipns --list
This will display a list of IPNS records with their corresponding keys and CIDs.
Remove an IPNS record:
lighthouse-web3 ipns --remove 8f4f116282a24cec99bcad73a317a3f4
This step allows you to remove an IPNS record if needed.
Step 0: Get API keys from Lighthouse as explained above.
Step 1: Import the Lighthouse package and set up your API key:
import lighthouse from '@lighthouse-web3/sdk';
const apiKey = process.env.API_KEY; // Replace this with your actual API key
Step 2: Generate an IPNS key using the Lighthouse SDK:
const keyResponse = await lighthouse.generateKey(apiKey);
console.log(keyResponse.data);
This will return an IPNS name and ID, which we will use in the next steps.
Step 3: Publish the content using the generated IPNS key and the CID:
const pubResponse = await lighthouse.publishRecord(
"QmWC9AkGa6vSbR4yizoJrFMfmZh4XjZXxvRDknk2LdJffc",
keyResponse.data.ipnsName,
apiKey
);
console.log(pubResponse.data);
You will receive a response containing the IPNS name and the link to access the published content.
Step 4: Get all IPNS keys associated with your Lighthouse account:
const allKeys = await lighthouse.getAllKeys(apiKey);
console.log(allKeys.data);
This step allows you to retrieve a list of all IPNS keys associated with your account.
Step 5: (Optional) Remove an IPNS key:
const removeRes = await lighthouse.removeKey(keyResponse.data.ipnsName, apiKey);
console.log(removeRes.data);
This step enables you to remove an IPNS key if necessary.
Lighthouse IPNS is a powerful mechanism for publishing and updating content on the IPFS network. By combining the benefits of content-addressing with the flexibility of mutable pointers, IPNS ensures your content remains accessible and updatable. In this guide, we covered two methods to utilize Lighthouse IPNS: the CLI and Node.js. Armed with this knowledge, you can confidently publish and manage IPNS records, creating a more dynamic and user-friendly experience on the decentralized web.
Remember to keep your API key secure and use it responsibly. Happy publishing!
Our Blogs
Read our latest blog
Nandit Mehra
Encryption and Access Control for Web3 using Lighthouse
Lighthouse
How To Migrate Your Files To Lighthouse
Nandit Mehra
Decentralized storage for the Ocean Protocol
Ravish Sharma
Creating a Pay-to-View Model Using Lighthouse Storage
Aryaman Raj
Getting Started with Lighthouse Python SDK
Aryaman Raj
A Comprehensive Guide to Publishing and Updating Content with Lighthouse IPNS
Aryaman Raj, Nandit Mehra
Time Lock Encryption using Lighthouse Access Control
Aryaman Raj
Secure File Sharing using Lighthouse SDK: A Step-by-Step Guide
Aryaman Raj
Passkey Demo App with WebAuthn and Ethereum
Ishika Rathi
Web3 Storage: IPFS and Filecoin Guide
Ishika Rathi
Understanding How web3 storage Operates
Ishika Rathi
Lighthouse: Secure Web3 Storage for Your AI Data
Ishika Rathi
Decentralized Storage: A Smarter, Safer, and Cheaper Way to Manage Your Data
Ishika Rathi
Unveiling the Mechanics of Perpetual Storage
Ishika Rathi
Navigating Permanent Storage: Harnessing the Power of Filecoin and IPFS
Ishika Rathi
Decentralized Excellence: Elevating Data Storage with Lighthouse
Ishika Rathi
Revolutionizing Permanence in Data Storage
Ishika Rathi
Eternalizing Data: A Permanent storage
Ishika Rathi
Exploring Web3 Advancements in Storage Solutions
Ishika Rathi
NFT Storage Strategies
Ishika Rathi
On-Chain Encryption: Security Unveiled
BananaCircle
Web2 Storage Challenges Versus Web3 Solutions Ft. Lighthouse
Nandit Mehra
Discover How the Endowment Pool Makes Your Data Immortal
Nandit Mehra
What is FHE and how Lighthouse plans to use it