> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dzap.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Check Allowance

> getAllowance() and the approval mode/permit type reference.

Before any swap/bridge/zap that spends ERC20s, a spender must be approved. The SDK supports several modes via `getAllowance()`, [Approve](/sdk/approvals/approve), and [Sign](/sdk/approvals/sign), pick `AutoPermit` unless you have a reason not to.

## The modes

`approve()`'s `mode` param takes an `ApprovalModes` value; `sign()`'s `permitType` param takes a `PermitTypes` value. They're closely related but not identical sets:

| `ApprovalModes` (for `approve()`) | `PermitTypes` (for `sign()`)     | How                                                                             | Spender          |
| --------------------------------- | -------------------------------- | ------------------------------------------------------------------------------- | ---------------- |
| `Default`                         | N/A                              | Standard ERC20 `approve()` transaction                                          | DZap router      |
| `PermitSingle`                    | `PermitSingle`                   | One-time approve to Permit2; sign a single-token Permit2 permit per trade       | Permit2 contract |
| `PermitWitnessTransferFrom`       | `PermitWitnessTransferFrom`      | One-time approve to Permit2; sign a witness-bound Permit2 transfer per trade    | Permit2 contract |
| `PermitBatchWitnessTransferFrom`  | `PermitBatchWitnessTransferFrom` | One-time approve to Permit2; sign one batched permit covering multiple tokens   | Permit2 contract |
| N/A                               | `EIP2612Permit`                  | Sign the token's native EIP-2612 permit message; no approval transaction at all | DZap router      |
| `AutoPermit`                      | `AutoPermit`                     | EIP-2612 if the token supports it, otherwise falls back to Permit2              | Auto             |

Most modern tokens support EIP-2612 or are routable through Permit2, so `AutoPermit` covers the long tail. `ApprovalModes` has no `EIP2612Permit` member, a token that supports EIP-2612 never needs an `approve()` call at all, only a `sign()` call.

## Check allowance

```ts theme={null}
import { ApprovalModes, Services } from '@dzapio/sdk';

const { status, data } = await dzap.getAllowance({
  chainId: 42161,
  sender: '0xUser',
  tokens: [{ address: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', amount: '1000000' }],
  service: Services.trade, // 'trade' | 'dca' | 'zap'
  mode: ApprovalModes.AutoPermit,
});

// data['0xaf88...'] => { allowance: bigint, type: 'dzap' | 'permit2' | 'eip2612' }
```

`type` tells you whether the token will use a direct DZap approval, a Permit2 approval, or an EIP-2612 permit. There is no `approvalNeeded`/`signatureNeeded` field, derive that yourself:

```ts theme={null}
const entry = data['0xaf88d065e77c8cC2239327C5EDb3A432268e5831'];
const needsApproval = entry.type !== 'eip2612' && entry.allowance < BigInt('1000000');
const needsSignature = entry.type !== 'dzap'; // permit2 and eip2612 both require a per-trade signature
```

## Recommended flow

<Steps>
  <Step title="Check">
    `getAllowance()` with `mode: AutoPermit`, then derive `needsApproval`/`needsSignature` from `allowance`/`type` as shown above.
  </Step>

  <Step title="Approve or sign">
    If `needsApproval`: [`approve()`](/sdk/approvals/approve). If `needsSignature`: [`sign()`](/sdk/approvals/sign).
  </Step>

  <Step title="Execute">
    Pass the resulting `permitData` (per-token) into the matching `data[].permitData` field of your `trade()`/`zap()` request.
  </Step>
</Steps>

## Common pitfalls

* **Multi-token operations**, `getAllowance` and `approve` both accept arrays. Don't loop one-by-one; you'll trigger N wallet popups.
* **Service must match**, `service: Services.trade` checks the trade router; `service: Services.zap` checks the zap router. They differ on some chains. `Services` only has `trade`, `dca`, and `zap`, there is no `'swap'` value.
* **Permit deadlines**, gasless permits include a deadline. Sign close to execution.

## Next steps

* [Approve](/sdk/approvals/approve)
* [Sign (gasless permits)](/sdk/approvals/sign)
* [Approval Mechanisms](/sdk/approval-mechanisms), deep dive on native token handling and permit modes
