đ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 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.
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).
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:
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:
Step 3: Publish this file to the IPFS using lighthouse upload:
Step 4: Publish the content using the generated IPNS key and the CID of the data you want to publish:
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.
Updating CID:
Upload another file text2.txt:
Publish this file to the IPFS using lighthouse upload:
Update the content using the generated IPNS key and the CID of the data you want to publish:
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:
This will display a list of IPNS records with their corresponding keys and CIDs.
Remove an IPNS record:
This step allows you to remove an IPNS record if needed.
Method 2: Using Node.js
Step 0: Get API keys from Lighthouse as explained above.
Step 1: Import the Lighthouse package and set up your API key:
Step 2: Generate an IPNS key using the Lighthouse SDK:
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:
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:
This step allows you to retrieve a list of all IPNS keys associated with your account.
Step 5: (Optional) Remove an IPNS key:
This step enables you to remove an IPNS key if necessary.
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 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!
Last updated