// store some data to publish constfs = unixfs(helia) constcid = awaitfs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
// publish the name const { publicKey } = awaitname.publish('key-1', cid)
// publish the recursive name const { publicKey: recursivePublicKey } = awaitname.publish('key-2', publicKey)
// resolve the name recursively - it resolves until a CID is found constresult = awaitname.resolve(recursivePublicKey) console.info(result.cid.toString() === cid.toString()) // true
Example: Publishing a record with a path
It is possible to publish CIDs with an associated path.
Additional IPNS routers can be configured - these enable alternative means to
publish and resolve IPNS names.
One example is the PubSub router - this requires an instance of Helia with
libp2p PubSub configured.
It works by subscribing to a pubsub topic for each IPNS name that we try to
resolve. Updated IPNS records are shared on these topics so an update must
occur before the name is resolvable.
This router is only suitable for networks where IPNS updates are frequent
and multiple peers are listening on the topic(s), otherwise update messages
may fail to be published with "Insufficient peers" errors.
// store some data to publish constfs = unixfs(helia) constcid = awaitfs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
// publish the name const { publicKey } = awaitname.publish('key-1', cid)
// resolve the name constresult = awaitname.resolve(publicKey)
Example: Republishing an existing IPNS record
It is sometimes useful to be able to republish an existing IPNS record
without needing the private key. This allows you to extend the availability
of a record that was created elsewhere.
IPNS operations using a Helia node
Example: Getting started
With IPNSRouting routers:
Example: Publishing a recursive record
A recursive record is a one that points to another record rather than to a value.
Example: Publishing a record with a path
It is possible to publish CIDs with an associated path.
Example: Using custom PubSub router
Additional IPNS routers can be configured - these enable alternative means to publish and resolve IPNS names.
One example is the PubSub router - this requires an instance of Helia with libp2p PubSub configured.
It works by subscribing to a pubsub topic for each IPNS name that we try to resolve. Updated IPNS records are shared on these topics so an update must occur before the name is resolvable.
This router is only suitable for networks where IPNS updates are frequent and multiple peers are listening on the topic(s), otherwise update messages may fail to be published with "Insufficient peers" errors.
Example: Republishing an existing IPNS record
It is sometimes useful to be able to republish an existing IPNS record without needing the private key. This allows you to extend the availability of a record that was created elsewhere.