useApproveERC20

Function: useApproveERC20()

useApproveERC20(tokenAddress, contractAddress, amount?, chainId?, enabled?): object

A custom hook for managing ERC-20 token approval to a specific contract. This hook includes functionality to check the current allowance, simulate the approval transaction, execute the approval, and track its status.

Parameters

tokenAddress

`0x${string}`

The address of the ERC-20 token to be approved.

contractAddress

`0x${string}`

The address of the contract to which the token is being approved.

amount?

bigint

The amount of tokens to approve. If not provided, it defaults to 0n.

chainId?

number

The ID of the blockchain network where the ERC-20 token resides.

enabled?

boolean = true

A flag to enable or disable the hook's functionality. When false, all queries and actions are disabled.

Returns

object

An object containing the following

allowance

allowance: undefined | bigint

approve()

approve: () => void

Returns

void

approveError

approveError: null | WriteContractErrorType

approveLoading

approveLoading: boolean

approveSuccess

approveSuccess: boolean

approveTxLoading

approveTxLoading: boolean

approveTxSuccess

approveTxSuccess: boolean

Defined in

packages/wagmi/src/hook/useApproveERC20.tsx:19

Last updated