token.watchTransfer
Watches for token transfer events on TIP20 tokens.
Usage
example.ts
import { Actions } from 'tempo.ts/wagmi'
import { config } from './wagmi.config'
const unwatch = Actions.token.watchTransfer(config, {
token: 1n,
onTransfer: (args, log) => {
console.log('Amount:', args.amount)
console.log('From:', args.from)
console.log('To:', args.to)
},
})
// Later, stop watching
unwatch()Return Type
type ReturnType = () => voidReturns a function to unsubscribe from the event.
Parameters
onTransfer
- Type:
function
declare function onTransfer(args: Args, log: Log): void
type Args = {
/** Amount transferred */
amount: bigint
/** Address sending the tokens */
from: Address
/** Address receiving the tokens */
to: Address
}Callback to invoke when tokens are transferred.
token
- Type:
Address | bigint
Address or ID of the TIP20 token to watch.
args (optional)
- Type:
object
type Args = {
/** Filter by sender address(es) */
from?: Address | Address[] | null
/** Filter by recipient address(es) */
to?: Address | Address[] | null
}Optional filter to watch only transfers from or to specific addresses.
fromBlock (optional)
- Type:
bigint
Block to start listening from.
onError (optional)
- Type:
function
declare function onError(error: Error): voidCallback to invoke when an error occurs while watching for new blocks.
poll (optional)
- Type:
true
Whether to use polling.
pollingInterval (optional)
- Type:
number
Polling frequency (in ms). Defaults to Client's pollingInterval config.