Skip to content
Docs
/
Hooks
/
useEnsResolver

useEnsResolver

Hook for fetching the resolver for ENS name.

import { useEnsResolver } from 'wagmi'

Usage

import { useEnsResolver } from 'wagmi'

function App() {
  const { data, isError, isLoading } = useEnsResolver({
    name: 'awkweb.eth',
  })

  if (isLoading) return <div>Fetching resolver…</div>
  if (isError) return <div>Error fetching resolver</div>
  return <div>Resolver: {JSON.stringify(data)}</div>
}

Return Values

{
  data?: EnsResolver
  error?: Error
  isError: boolean
  isFetched: boolean
  isFetching: boolean
  isIdle: boolean
  isLoading: boolean
  isRefetching: boolean
  isStale: boolean
  isSuccess: boolean
  refetch: (options: {
    throwOnError: boolean
    cancelRefetch: boolean
  }) => Promise<EnsResolver>
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

name (optional)

ENS name to fetch address for. If name is not defined, hook will not run.

import { useEnsResolver } from 'wagmi'

function App() {
  const ensResolver = useEnsResolver({
    name: 'moxey.eth',
  })
}

cacheTime (optional)

Time (in ms) which the data should remain in the cache. Defaults to 0.

import { useEnsResolver } from 'wagmi'

function App() {
  const ensResolver = useEnsResolver({
    name: 'awkweb.eth',
    cacheTime: 2_000,
  })
}

enabled (optional)

Set this to false to disable this query from automatically running. Defaults to true.

import { useEnsResolver } from 'wagmi'

function App() {
  const ensResolver = useEnsResolver({
    name: 'awkweb.eth',
    enabled: false,
  })
}

staleTime (optional)

Time (in ms) after data is considered stale. If set to Infinity the data will never be considered stale. Defaults to 60 * 60 * 24 (24 hours).

import { useEnsResolver } from 'wagmi'

function App() {
  const ensResolver = useEnsResolver({
    name: 'awkweb.eth',
    staleTime: 2_000,
  })
}

suspense (optional)

Set this to true to enable suspense mode.

import { useEnsResolver } from 'wagmi'

function App() {
  const ensResolver = useEnsResolver({
    name: 'awkweb.eth',
    suspense: true,
  })
}

onSuccess (optional)

Function to invoke when fetching new data is successful.

import { useEnsResolver } from 'wagmi'

function App() {
  const ensResolver = useEnsResolver({
    name: 'awkweb.eth',
    onSuccess(data) {
      console.log('Success', data)
    },
  })
}

onError (optional)

Function to invoke when an error is thrown while fetching new data.

import { useEnsResolver } from 'wagmi'

function App() {
  const ensResolver = useEnsResolver({
    name: 'awkweb.eth',
    onError(error) {
      console.log('Error', error)
    },
  })
}

onSettled (optional)

Function to invoke when fetching is settled (either successfully fetched, or an error has thrown).

import { useEnsResolver } from 'wagmi'

function App() {
  const ensResolver = useEnsResolver({
    name: 'awkweb.eth',
    onSettled(data, error) {
      console.log('Settled', { data, error })
    },
  })
}