helia
    Preparing search index...

    Module @helia/dnslink

    DNSLink operations using a Helia node.

    To use custom resolvers, configure Helia's dns option:

    import { createHelia } from 'helia'
    import { dnsLink } from '@helia/dnslink'
    import { dns } from '@multiformats/dns'
    import { dnsOverHttps } from '@multiformats/dns/resolvers'
    import type { DefaultLibp2pServices } from 'helia'
    import type { Libp2p } from '@libp2p/interface'

    const node = await createHelia<Libp2p<DefaultLibp2pServices>>({
    dns: dns({
    resolvers: {
    '.': dnsOverHttps('https://private-dns-server.me/dns-query')
    }
    })
    })
    const name = dnsLink(node)

    const result = name.resolve('some-domain-with-dnslink-entry.com')

    Example: Resolving a domain with a dnslink entry

    Calling resolve with the @helia/dnslink instance:

    // resolve a CID from a TXT record in a DNS zone file, using the default
    // resolver for the current platform eg:
    // > dig _dnslink.ipfs.tech TXT
    // ;; ANSWER SECTION:
    // _dnslink.ipfs.tech. 60 IN CNAME _dnslink.ipfs-tech.on.fleek.co.
    // _dnslink.ipfs-tech.on.fleek.co. 120 IN TXT "dnslink=/ipfs/bafybe..."

    import { createHelia } from 'helia'
    import { dnsLink } from '@helia/dnslink'

    const node = await createHelia()
    const name = dnsLink(node)

    const [{ answer }] = await name.resolve('blog.ipfs.tech')

    console.info(answer)
    // { data: '/ipfs/bafybe...' }

    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.

    import { createHelia } from 'helia'
    import { dnsLink } from '@helia/dnslink'
    import { dns } from '@multiformats/dns'
    import { dnsOverHttps } from '@multiformats/dns/resolvers'
    import type { DefaultLibp2pServices } from 'helia'
    import type { Libp2p } from '@libp2p/interface'

    const node = await createHelia<Libp2p<DefaultLibp2pServices>>({
    dns: dns({
    resolvers: {
    '.': dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
    }
    })
    })
    const name = dnsLink(node)

    const result = await name.resolve('blog.ipfs.tech')

    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.

    import { createHelia } from 'helia'
    import { dnsLink } from '@helia/dnslink'
    import { dns } from '@multiformats/dns'
    import { dnsJsonOverHttps } from '@multiformats/dns/resolvers'
    import type { DefaultLibp2pServices } from 'helia'
    import type { Libp2p } from '@libp2p/interface'

    const node = await createHelia<Libp2p<DefaultLibp2pServices>>({
    dns: dns({
    resolvers: {
    '.': dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
    }
    })
    })
    const name = dnsLink(node)

    const result = await name.resolve('blog.ipfs.tech')

    Interfaces

    DNSLinkComponents
    DNSLinkIPFSResult
    DNSLinkIPNSResult
    DNSLinkNamespace
    DNSLinkOptions
    DNSLinkOtherResult
    ResolveDNSLinkOptions

    Type Aliases

    DNSLinkResult

    Functions