Skip to content

Components

Approve Button

ERC-20 approval gate. Shows "Approve" until the allowance covers the amount, then your action.

Wrap the action that spends a token. While the allowance is too low it shows “Approve USDC” as a Transaction Button. Once the approval is mined, it renders your action instead. If the allowance already covers the amount, it skips straight to the action.

Connect the Demo Wallet to try it.

Terminal window
npx shadcn@latest add @0xui/approve-button
import { ApproveButton } from "@/components/approve-button";
<ApproveButton token={usdc} spender={router} amount={amount} chainId={1}>
<TransactionButton chainId={1} contract={swapCall}>Swap</TransactionButton>
</ApproveButton>;

By default it approves exactly amount. That’s safest: the spender can’t move more than this action needs. unlimited approves the maximum, which saves future approvals but lets the spender move all of the token. If you offer it, let the user choose.

<ApproveButton unlimited={rememberApproval} …>

Some tokens refuse to change a non-zero allowance to another non-zero value. USDT on mainnet is the well-known one. When such a token has a leftover allowance that is too low, the button first shows “Reset USDT approval”, which sets it to 0, and then “Approve USDT”. That is two transactions.

Mainnet USDT is detected by address. For any other token that behaves this way, pass resetFirst:

<ApproveButton token={token} spender={router} amount={amount} chainId={1} resetFirst>
{action}
</ApproveButton>

Also accepts Transaction Button props such as onSuccess and variant.

Prop Type Default Description
token { address, symbol } — Token to approve.
spender Address — Contract that will spend it.
amount bigint — Amount the action needs.
chainId number — Chain the token is on.
unlimited boolean false Approve the maximum.
resetFirst boolean true for mainnet USDT Set a leftover allowance to 0 before raising it.
children ReactNode — Shown once approved.

Headless: useAllowance({ token, spender }).