event.watch
Watches one name's ENS events as new blocks arrive. Parameters, return value, errors and examples for event.watch in @ensforge/sdk.
Watches one name's ENS events as new blocks arrive. Resolves to a function that stops watching.
When to use
Use to update a name's page live, or to react when another account changes the name.
Details
- Every new block range is read like
event.get, so resolver and registry changes during the watch are followed. - Polls at the public client's
pollingIntervalunlesspollingIntervalis given.
Signature
function watch(client: Like, options: watch.Options): Promise<watch.ReturnType>Call it as ens.event.watch(options) on a client, or Actions.event.watch(client, options).
Parameters
| Option | Type | Default | Description |
|---|---|---|---|
name (required) | string | ENS name. Normalized automatically. | |
types | readonly EventType[] | Only these event types. | |
pollingInterval | number | Milliseconds between polls. | |
onEvents (required) | (events: readonly Event[]) => void | Called with each new batch of events. | |
onError | ((error: AnyError) => void) | Called when a poll fails; watching continues. |
Returns
Resolves to () => void. Stops watching.
Errors
| Error | Codes | When |
|---|---|---|
InvalidInputError | INVALID_NAME | invalid names. |
It can also fail with the errors every read can (Errors.CommonError: ConfigError, ContractRevertError, InternalError, NetworkError).
See How errors work.
Examples
const unwatch = await ens.event.watch({ name: "nick.eth", onEvents: (events) => console.log(events) })See also
event.getto read past events
Was this page helpful?