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 Value
{
data?: EnsResolver
error?: Error
isIdle: boolean
isLoading: boolean
isFetching: boolean
isSuccess: boolean
isError: boolean
isFetched: boolean
isFetchedAfterMount: boolean
isRefetching: boolean
refetch: (options: {
throwOnError: boolean
cancelRefetch: boolean
}) => Promise<EnsResolver>
status: 'idle' | 'error' | 'loading' | 'success'
}
Configuration
chainId (optional)
Force a specific chain id for the request. The wagmi Client
's ethers provider
must be set up as a chain-aware function for this to work correctly.
import { useEnsResolver } from 'wagmi'
function App() {
const ensResolver = useEnsResolver({
name: 'awkweb.eth',
chainId: 1,
})
}
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',
})
}
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,
})
}
scopeKey (optional)
Scopes the cache to a given context. Hooks that have identical context will share the same cache.
import { useEnsResolver } from 'wagmi'
function App() {
const ensResolver = useEnsResolver({
name: 'awkweb.eth',
scopeKey: 'wagmi',
})
}
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 })
},
})
}