token.watchRole
Watches for role membership update events on TIP20 tokens.
Usage
import { } from './viem.config'
const = .token.watchRole({
: '0x...', // Address or ID of the TIP20 token
: (, ) => {
.('Account:', .account)
.('Has role:', .hasRole)
.('Role:', .role)
.('Type:', .type) // 'granted' or 'revoked'
.('Sender:', .sender)
},
})
// Later, stop watching
()Return Type
type ReturnType = () => voidReturns a function to unsubscribe from the event.
Parameters
onRoleUpdated
- Type:
function
declare function onRoleUpdated(args: Args, log: Log): void
type Args = {
/** Role being updated */
role: Hex
/** Account receiving or losing the role */
account: Address
/** Address that updated the role */
sender: Address
/** Whether the account has the role */
hasRole: boolean
/** Type of role update */
type: 'granted' | 'revoked'
}Callback to invoke when a role membership is updated.
token
- Type:
Address | bigint
Address or ID of the TIP20 token.
args (optional)
- Type:
object
type Args = {
/** Filter by role */
role?: Hex | Hex[] | null
/** Filter by account */
account?: Address | Address[] | null
/** Filter by sender */
sender?: Address | Address[] | null
}Filter parameters for the watch subscription.
fromBlock (optional)
- Type:
bigint
Block to start listening from.
onError (optional)
- Type:
function
declare function onError(error: Error): voidThe callback to call when an error occurred when trying to get for a new block.
poll (optional)
- Type:
true
Whether to use polling.
pollingInterval (optional)
- Type:
number
Polling frequency (in ms). Defaults to Client's pollingInterval config.