Skip to content

API ReferenceReact provider and hooksFunction

useResolveAddress()

function useResolveAddress(): object;

Hook that returns the resolveAddress action configured with the current Anvil SDK context. Address-or-ENS input resolution is protocol-specific orchestration (it backs AddressInput), not a general ENS query — consumers with a fully wagmi-configured mainnet connection lose nothing by resolving addresses their own way.

This is a thin context-binder, not a data-fetching hook: it returns a stable callback, not cached/query state. Prefer this over rolling your own sdk.resolveAddress(...) call when you already have useAnvilSDK context available.

Rejection contract: the returned callback’s promise rejects exactly as the core resolveAddress action documents (a typed ProviderConnectionError on ENS RPC failure); undefined is the domain “does not resolve” outcome. Callers own the catch — the binder never swallows errors.

Returns

object

An object whose resolveAddress is a stable callback taking an address or ENS name and resolving to the checksummed address, or undefined when the input does not resolve.

resolveAddress

resolveAddress: value => Promise<`0x${string}` | undefined>;

Parameters

ParameterType
valuestring

Returns

Promise<`0x${string}` | undefined>

Throws

Error when rendered outside <AnvilProvider>, by way of useAnvilSDK.

Example

export function BeneficiaryField() {
const { resolveAddress } = useResolveAddress();
const [resolved, setResolved] = useState<Address>();
const [lookupFailed, setLookupFailed] = useState(false);
async function onBlur(value: string) {
// Catch here: an async event handler that lets the promise reject
// produces an unhandled rejection. `undefined` is the domain "does
// not resolve" outcome and a rejection is the ENS lookup failing --
// only the second is worth retrying, so they get separate state.
setLookupFailed(false);
try {
setResolved(await resolveAddress(value));
} catch {
setResolved(undefined);
setLookupFailed(true);
}
}
return (
<>
<input
onBlur={event => onBlur(event.target.value)}
placeholder={resolved ?? 'vitalik.eth or 0x…'}
/>
{lookupFailed && <p>ENS lookup unavailable. Try again.</p>}
</>
);
}