# Check ERC-20 Allowance

Read the on-chain ERC-20 allowance a wallet has granted to a spender — typically the `approvalAddress` from the quote.

## Overview

The API calls `allowance(owner, spender)` on `tokenAddress`, where `owner` is the address of `walletId` and `spender` is `spenderAddress`. The lookup runs on `chain`, or on the wallet's own chain when `chain` is omitted.

[Get Quote](https://docs.aureahub.com/docs/swap-quote.md) already performs this check against its `approvalAddress` and returns the result as `needsApproval`. Call this endpoint when you need a fresh reading — for example after broadcasting a non-custodial approval, because approvals do not create a transaction record you could poll.

> ⚠️ `needsApproval` is `true` only when the allowance is exactly `0`; it is not compared with the amount you intend to swap. If you approved a specific amount, compare `allowance` (an integer string in the token's smallest unit) with your amount yourself. `requiredAmount` is declared in the response schema but is not populated.

> ℹ️ Solana has no ERC-20 allowance. When the target chain is `solana`, the API returns `{ "allowance": "not_applicable", "needsApproval": false }` without reading the chain.

## Endpoint

### `POST /v1/swap/check-allowance`

Authentication: bearer token required.

Reads the current ERC-20 allowance of a wallet for a spender.

**Request body**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `walletId` | string (uuid) | yes | Token owner wallet. Must belong to the authenticated user. |
| `tokenAddress` | string | yes | Token contract address: `0x` + 40 hex characters (the schema also accepts a Solana base58 address). |
| `spenderAddress` | string | yes | Spender to check, `0x` + 40 hex characters — use `approvalAddress` from the quote. |
| `chain` | string | no | Chain to read from. Defaults to the wallet's chain. |
| `isTestnet` | boolean | no | Read from the testnet of the chain. Defaults to `false`. |

**Responses**

`200` OK

```json
{
  "allowance": "0",
  "needsApproval": true
}
```

`200` Solana

```json
{
  "allowance": "not_applicable",
  "needsApproval": false
}
```

`400` Bad Request

```json
{
  "statusCode": 400,
  "error": "BadRequestError",
  "message": "Failed to check token allowance"
}
```

`404` Not Found

```json
{
  "statusCode": 404,
  "error": "NotFoundError",
  "message": "Wallet not found"
}
```

Other `400` responses: `Request validation failed` (body does not match the schema), `Unsupported chain: …`, and `Network mismatch: …` when the RPC for the chain reports a different chain ID.

## Implementation

```javascript
async function getAllowance(token, { walletId, tokenAddress, spenderAddress, chain }) {
  const res = await fetch('https://api.aureahub.com/v1/swap/check-allowance', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    },
    body: JSON.stringify({ walletId, tokenAddress, spenderAddress, chain })
  });
  const body = await res.json();
  if (!res.ok) throw new Error(`${res.status}: ${body.message}`);
  return body; // { allowance, needsApproval }
}

// Is the allowance enough for a specific amount (token's smallest unit)?
const { allowance } = await getAllowance(token, {
  walletId,
  tokenAddress: FROM_TOKEN,
  spenderAddress: quote.approvalAddress,
  chain: 'polygon'
});
const enough = allowance === 'not_applicable' || BigInt(allowance) >= BigInt(requiredAmount);
```

---

Web version: https://docs.aureahub.com/#swap-allowance
