Watch Access Key Admin Authorizations
accessKey.watchAdminAuthorized
Watches AdminKeyAuthorized events on the account keychain.
Usage
import { } from './viem.config'
const = ..()
.(() => {
for (const of ) .(.)
{ account: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb', publicKey: '0x8ba1f109551bD432803012645Ac136ddd64DBA72' }
})
// Later, tear down the watcher.
.()import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Also callable standalone: Actions.accessKey.watchAdminAuthorized(client, options), with Actions imported from 'viem/tempo'.
Recipes
Auto-Revoke Unexpected Admin Grants
Filter args to your account and revoke any admin key you did not provision with accessKey.revoke.
import { } from './viem.config'
// Admin keys provisioned through your ops workflow.
const = new <string>([
'0x8ba1f109551bD432803012645Ac136ddd64DBA72',
])
const = ..({
: { : .. },
})
.(async () => {
for (const of ) {
if (.(..)) continue
// Unexpected admin grant: revoke immediately.
await ..({ : .. })
}
})import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
Returns a watcher handle. Watching starts when the first listener (or async iterator) attaches, and stops when off is called.
type ReturnType = {
/** Registers a log listener. Starts the watcher on first registration. Returns an unregister function. */
onLogs: (fn: (logs: readonly Log[]) => void) => () => void
/** Registers an error listener. Returns an unregister function. */
onError: (fn: (error: Error) => void) => () => void
/** Tears down the watcher: removes listeners, ends iterators, stops the poll or subscription. */
off: () => void
/** Async-iterates emitted log batches (latest-only stream). */
[Symbol.asyncIterator]: () => AsyncIterableIterator<{ logs: readonly Log[] }>
}Each log is decoded, with the event arguments on args:
type Log = {
/** Decoded `AdminKeyAuthorized` event arguments. */
args: {
account: Address
publicKey: Address
}
/** Name of the emitted event. */
eventName: 'AdminKeyAuthorized'
// ...standard log fields (address, blockHash, blockNumber, logIndex, transactionHash, ...)
}Parameters
args
- Type:
object
type Args = {
account?: Address | Address[] | null
publicKey?: Address | Address[] | null
}Indexed argument values to filter logs by.
batch
- Type:
boolean - Default:
true
Whether to batch the logs found within a poll interval into a single emission. When false, each log is emitted on its own.
fromBlock
- Type:
bigint
Block number from which to start watching for logs.
poll
- Type:
boolean
Whether to poll for new logs instead of using a subscription. Defaults to true when the transport cannot subscribe or fromBlock is provided.
pollingInterval
- Type:
number - Default:
client.pollingInterval
Polling frequency (in ms).