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

# Approve Token Spending

Allow a smart contract (DEX, protocol, etc.) to spend your tokens. Required before swaps, staking, or DeFi interactions. Set amount to 0 to revoke an existing approval.

![Approve Token Spending logo](https://ai-icon.b3.fun/logo/ethereum)
Catalog action EVM Onchain wallet Gas

Allow a smart contract (DEX, protocol, etc.) to spend your tokens. Required before swaps, staking, or DeFi interactions. Set amount to 0 to revoke an existing approval.

**Review wallet and value movement**

This action can require a wallet connector, gas, token movement, or an external side effect. Test with simulation or a controlled amount before using it in a live workflow.

## At a Glance

| Field | Value |
| --- | --- |
| Action ID | `approve-erc20` |
| Category | EVM Onchain |
| Connector | `wallet` |
| Requires gas | Yes |
| Funds movement | None declared |
| Tags | `blockchain`, `evm`, `erc20`, `token`, `approve`, `allowance`, `defi`, `permission`, `swap` |

## Payload Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `tokenAddress` | `string` | Yes | ERC20 token contract address |
| `spenderAddress` | `string` | Yes | Address being approved to spend tokens \(e.g., DEX router\) |
| `amount` | `string` | Yes | Amount to approve in token smallest units \(e.g., "1000000" for 1 USDC\). Use max uint256 for unlimited approval. |
| `chainId` | `number` | Yes | Chain ID \(1=Ethereum, 137=Polygon, 56=BSC, 8453=Base, etc.\) |
| `gasLimit` | `string` | No | Optional gas limit override |
| `confirmUnlimitedApproval` | `boolean` | No | Required confirmation flag when approving unlimited \(max uint256\) amounts. Set to true to acknowledge the security risk. |

## Result Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `status` | `string` | Yes | - |
| `transactionHash` | `string` | Yes | - |
| `approvedAmount` | `string` | No | The amount that was approved |
| `isUnlimitedApproval` | `boolean` | No | Whether this was an unlimited approval \(max uint256\) |
| `blockNumber` | `number` | No | Block number the transaction was included in |

## Examples

**Workflow node**

```json
{
  "type": "approve-erc20",
  "payload": {
    "tokenAddress": "0x0000000000000000000000000000000000000000",
    "spenderAddress": "0x0000000000000000000000000000000000000000",
    "amount": "1000000",
    "chainId": 8453
  },
  "children": [],
  "connector": {
    "type": "wallet",
    "id": "conn_wallet"
  }
}
```
  **Test with API**

```bash
curl -X POST "https://api.b3os.org/v1/actions/approve-erc20/test" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "tokenAddress": "0x0000000000000000000000000000000000000000",
    "spenderAddress": "0x0000000000000000000000000000000000000000",
    "amount": "1000000",
    "chainId": 8453
  }
}'
```

**Use expressions for dynamic values**

Payload fields can use workflow expressions such as `{{$trigger.body.amount}}`, `{{$nodes.fetch.result.price}}`, and `{{$props.asset}}` when the value should come from a trigger, prior node, or reusable workflow prop.