Skip to content

token.watchApprove ​

Watches for token approval events on TIP20 tokens.

Usage ​

ts
import { Actions } from 'wagmi/tempo'
import { config } from './config'

const unwatch = Actions.token.watchApprove(config, {
  token: 0n,
  onApproval(args, log) {
    console.log('args:', args)
  },
})

// Later, stop watching
unwatch()
ts
import { createConfig, http } from 'wagmi'
import { tempo } from 'wagmi/chains'
import { tempoWallet } from 'wagmi/tempo'

export const config = createConfig({
  connectors: [tempoWallet()],
  chains: [tempo],
  multiInjectedProviderDiscovery: false,
  transports: {
    [tempo.id]: http(),
  },
})

Return Type ​

() => void

Returns a function to unsubscribe from the event.

Parameters ​

onApproval ​

  • Type: function
ts
declare function onApproval(args: Args, log: Log): void

type Args = {
  /** Amount approved */
  amount: bigint
  /** Address of the token owner */
  owner: Address
  /** Address of the spender */
  spender: Address
}

Callback to invoke when tokens are approved.

token ​

  • Type: Address | bigint

Address or ID of the TIP20 token to watch.

args (optional) ​

  • Type: object
ts
type Args = {
  /** Filter by token owner address */
  owner?: Address | Address[] | null
  /** Filter by spender address */
  spender?: Address | Address[] | null
}

Filter events by owner and/or spender addresses.

fromBlock (optional) ​

  • Type: bigint

Block to start listening from.

onError (optional) ​

  • Type: function
ts
declare function onError(error: Error): void

The callback to call when an error occurred when trying to get for a new block.

poll (optional) ​

  • Type: true

Enable polling mode.

pollingInterval (optional) ​

  • Type: number

Polling frequency (in ms). Defaults to Client's pollingInterval config.

Viem ​

Released under the MIT License.