
πUpdate Content with Lighthouse IPNS
A Comprehensive Guide to Publishing and Updating Content with Lighthouse IPNS
Introduction:
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 three methods to publish and update content with Lighthouse IPNS: using the CLI (Command Line Interface), Node.js, and Go SDK. By the end of this guide, you will be able to effectively publish and manage IPNS records, making your content easily accessible and updatable.
Prerequisites:
Before we get started, ensure you have the following:
Node.js installed on your system (for Node.js method).
Lighthouse CLI installed (for CLI method).
Go installed on your system (for Go method).
Understanding Mutability in IPFS:
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:
Anatomy of an IPNS Name: An IPNS name is essentially the hash of a public key. It is associated with an IPNS record that contains various information, including the content path (/ipfs/CID) it links to, expiration details, version number, and a cryptographic signature signed by the corresponding private key. The owner of the private key can sign and publish new records at any time.
IPNS Names and Content Paths: IPNS records can point to either immutable or mutable paths. When using IPNS, the CID's meaning in the path depends on the namespace used:
/ipfs/<cid>: Refers to immutable content on IPFS, with the CID containing a multihash./ipns/<cid-of-libp2p-key>: Represents a mutable, cryptographic IPNS name that corresponds to a libp2p public key.
Note: Skip to Store and Update content on IPNS using Lighthouseif you already have a Lighthouse API Key
Step 0: Getting your lighthouse API key Files-Lighthouse-storage:
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

Store and Update content on IPNS using Lighthouse
Method 1: Using Lighthouse CLI
Step 1: Generate an IPNS key using the Lighthouse CLI:
lighthouse-web3 ipns --generate-keyThis 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=QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8uYou 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.

Updating CID:
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=QmanCeGkwsaCUHaNT24ndriYTYSwZuAy4JDifdYZpHdmRaYou 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 --listThis will display a list of IPNS records with their corresponding keys and CIDs.

Remove an IPNS record:
lighthouse-web3 ipns --remove 8f4f116282a24cec99bcad73a317a3f4This step allows you to remove an IPNS record if needed.

Method 2: Using Node.js
For detailed instructions on using Node.js SDK, see the Node.js section.
Method 3: Using Go SDK
For detailed instructions on using Go SDK, see the Go SDK section.
Conclusion
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 three methods to utilize Lighthouse IPNS: the CLI (JavaScript/TypeScript), Node.js (JavaScript/TypeScript), and Go SDK. 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!
Last updated
Was this helpful?