// create a public key to publish as an IPNS name constkeyInfo = awaithelia.libp2p.services.keychain.createKey('my-key') constpeerId = awaithelia.libp2p.services.keychain.exportPeerId(keyInfo.name)
// store some data to publish constfs = unixfs(helia) constcid = awaitfs.add(Uint8Array.from([0, 1, 2, 3, 4]))
// publish the name awaitname.publish(peerId, cid)
// resolve the name constcid = name.resolve(peerId)
// resolve a CID from a TXT record in a DNS zone file, using the default // resolver for the current platform eg: // > dig _dnslink.ipfs.io TXT // ;; ANSWER SECTION: // _dnslink.ipfs.io. 60 IN TXT "dnslink=/ipns/website.ipfs.io" // > dig _dnslink.website.ipfs.io TXT // ;; ANSWER SECTION: // _dnslink.website.ipfs.io. 60 IN TXT "dnslink=/ipfs/QmWebsite"
constcid = name.resolveDns('ipfs.io')
console.info(cid) // QmWebsite
Example: Using DNS-Over-HTTPS
This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This
uses binary DNS records so requires extra dependencies to process the
response which can increase browser bundle sizes.
If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
// use DNS-Over-HTTPS import { dnsOverHttps } from'@helia/ipns/dns-resolvers'
IPNS operations using a Helia node
Example: Using libp2p and pubsub routers
With IPNSRouting routers:
Example: Using custom DNS over HTTPS resolvers
With default DNSResolver resolvers:
Example: Resolving a domain with a dnslink entry
Calling
resolveDns
with the@helia/ipns
instance:Example: Using DNS-Over-HTTPS
This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This uses binary DNS records so requires extra dependencies to process the response which can increase browser bundle sizes.
If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
Example: Using DNS-JSON-Over-HTTPS
DNS-JSON-Over-HTTPS resolvers use the RFC 8427
application/dns-json
and can result in a smaller browser bundle due to the response being plain JSON.