πIPNS - Handle Mutable Data
Using IPNS to handle mutable data
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
Create an IPNS key
Map the IPNS key with a CID
In case of CID change just update the mapping, the IPNS key remains the same
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
Step 4: Remove an IPNS Key
Step 5: Update an IPNS Key
Step 1: Create a New IPNS Key
Upon successful creation, you will receive an IPNS name and its corresponding ID.
Step 2: Publish an IPFS Hash to IPNS
The response will show the IPNS name and the IPFS path it points to.
Step 3: Retrieve All IPNS Keys
Step 4: Update an IPNS Key
To update an IPNS key, simply publish a new CID to the same IPNS name:
Step 5: Remove an IPNS Key
Step 1: Create a New IPNS Key
Upon successful creation, you will receive an IPNS name and its corresponding ID.
Step 2: Publish an IPFS Hash to IPNS
The response will show the IPNS name and the IPFS path it points to.
Step 3: Retrieve All IPNS Keys
Step 4: Update an IPNS Key
To update an IPNS key, simply publish a new CID to the same IPNS name:
Step 5: Remove an IPNS Key
Last updated
Was this helpful?