> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Approve Spending \[token.approve]

Approves a spender to transfer an ERC-20 token, waits for the transaction receipt, and returns the
decoded `Approval` event.

## Usage

Use `approveSync` to approve token spending and wait for the decoded `Approval` event.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const { owner, spender, value, receipt } = await client.token.approveSync({
  amount: 250000000n,
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
// @log: { owner: '0x…', spender: '0x1111…', value: 250000000n, decimals: 6, formatted: '250', receipt: { … } }
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Account, Client, http, walletActions } from 'viem'
import { mainnet } from 'viem/chains'
import { usdc } from 'viem/tokens'

export const client = Client.create({
  account: Account.fromPrivateKey('0x…'),
  chain: mainnet,
  tokens: [usdc],
  transport: http(),
}).extend(walletActions())
```
:::

### Asynchronous Usage

Use `approve` when the transaction hash is needed immediately and receipt tracking happens
elsewhere.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const hash = await client.token.approve({
  amount: 250000000n,
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
// @log: "0x4ca7ee652d57678f26e887c19671f76c1aff..."
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Account, Client, http, walletActions } from 'viem'
import { mainnet } from 'viem/chains'
import { usdc } from 'viem/tokens'

export const client = Client.create({
  account: Account.fromPrivateKey('0x…'),
  chain: mainnet,
  tokens: [usdc],
  transport: http(),
}).extend(walletActions())
```
:::

### Standalone Action

Call `Actions.token.approveSync` directly by passing the Client as the first argument. Use
`Actions.token.approve` for the asynchronous variant.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem'
import { client } from './viem.config'

const { owner, spender, value, receipt } = await Actions.token.approveSync(client, {
  amount: 250000000n,
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
// @log: { owner: '0x…', spender: '0x1111…', value: 250000000n, decimals: 6, formatted: '250', receipt: { … } }
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Account, Client, http } from 'viem'
import { mainnet } from 'viem/chains'
import { usdc } from 'viem/tokens'

export const client = Client.create({
  account: Account.fromPrivateKey('0x…'),
  chain: mainnet,
  tokens: [usdc],
  transport: http(),
})
```
:::

## Recipes

### Approve a Formatted Amount

Declare the token on the Client to select it by symbol. Viem uses the declared decimals to convert
the formatted amount to base units.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const hash = await client.token.approve({
  amount: { formatted: '250' }, // [!code focus]
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: 'usdc', // [!code focus]
})
// @log: "0x4ca7ee652d57678f26e887c19671f76c1aff..."
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Account, Client, http, walletActions } from 'viem'
import { mainnet } from 'viem/chains'
import { usdc } from 'viem/tokens'

export const client = Client.create({
  account: Account.fromPrivateKey('0x…'),
  chain: mainnet,
  tokens: [usdc],
  transport: http(),
}).extend(walletActions())
```
:::

### Approve a Token by Address

When the Client does not declare the token, pass its contract address. Include the token decimals
when using a formatted amount.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const hash = await client.token.approve({
  amount: { // [!code focus]
    decimals: 6, // [!code focus]
    formatted: '250', // [!code focus]
  }, // [!code focus]
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // [!code focus]
})
// @log: "0x4ca7ee652d57678f26e887c19671f76c1aff..."
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Account, Client, http, walletActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  account: Account.fromPrivateKey('0x…'),
  chain: mainnet,
  transport: http(),
}).extend(walletActions())
```
:::

## Return Value

### Synchronous

`{ owner, spender, value, decimals?, formatted?, receipt }`

The decoded `Approval` event args, transaction receipt, and formatted amount when the token's
decimals are known.

### Asynchronous

`Hex`

The transaction hash.

## Parameters

### account

* **Type:** `Account | Address`
* **Default:** `client.account`

The account to approve from.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const hash = await Actions.token.approve(client, {
  account: Account.fromPrivateKey('0x…'), // [!code focus]
  amount: 250000000n,
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
```

### amount

* **Type:** `bigint | { decimals?: number; formatted: string }`

The amount to approve, in base units (`bigint`) or as a formatted helper. When `formatted` is given, `decimals` is taken from the helper, the declared token, or fetched.

```ts twoslash
// @noErrors
import { Client, http, walletActions } from 'viem'
import { mainnet } from 'viem/chains'
import { usdc } from 'viem/tokens'

const client = Client.create({
  chain: mainnet,
  tokens: [usdc],
  transport: http(),
}).extend(walletActions())
// ---cut---
const hash = await client.token.approve({
  amount: { formatted: '250' }, // [!code focus]
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: 'usdc',
})
```

#### decimals

* **Type:** `number`

Token decimals used to parse a formatted `amount`. When omitted, decimals are taken from a declared token, or fetched from the contract.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const hash = await Actions.token.approve(client, {
  amount: { decimals: 6, formatted: '250' }, // [!code focus]
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
```

### chain

* **Type:** `Chain | null`
* **Default:** `client.chain`

The target chain. Pass `null` to skip the current-chain assertion.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const hash = await Actions.token.approve(client, {
  amount: 250000000n,
  chain: mainnet, // [!code focus]
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
```

### gas

* **Type:** `bigint | Hex`

The gas limit for the transaction.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const hash = await Actions.token.approve(client, {
  amount: 250000000n,
  gas: 50_000n, // [!code focus]
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
```

### maxFeePerGas

* **Type:** `bigint | number | Hex`

The maximum total fee per gas.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const hash = await Actions.token.approve(client, {
  amount: 250000000n,
  maxFeePerGas: 30_000_000_000n, // [!code focus]
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
```

### maxPriorityFeePerGas

* **Type:** `bigint | number | Hex`

The maximum priority fee per gas.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const hash = await Actions.token.approve(client, {
  amount: 250000000n,
  maxPriorityFeePerGas: 1_000_000_000n, // [!code focus]
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
```

### nonce

* **Type:** `bigint | Hex`

The transaction nonce.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const hash = await Actions.token.approve(client, {
  amount: 250000000n,
  nonce: 12n, // [!code focus]
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
```

### spender

* **Type:** `Address`

The spender to approve.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const hash = await Actions.token.approve(client, {
  amount: 250000000n,
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582', // [!code focus]
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
```

### throwOnReceiptRevert

* **Type:** `boolean`
* **Default:** `true`

Whether `approveSync` throws if the transaction receipt indicates a revert.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const result = await Actions.token.approveSync(client, {
  amount: 250000000n,
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  throwOnReceiptRevert: false, // [!code focus]
  token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
})
```

### token

* **Type:** `Address | string`

The token to approve: a contract `address`, or a symbol declared on the client's [`tokens`](/docs/clients/create) array.

```ts twoslash
// @noErrors
import { Client, http, walletActions } from 'viem'
import { mainnet } from 'viem/chains'
import { usdc } from 'viem/tokens'

const client = Client.create({
  chain: mainnet,
  tokens: [usdc],
  transport: http(),
}).extend(walletActions())
// ---cut---
const hash = await client.token.approve({
  amount: 250000000n,
  spender: '0x1111111254EEB25477B68fb85Ed929f73A960582',
  token: 'usdc', // [!code focus]
})
```

## Errors

| Error | Description |
| --- | --- |
| `Account.NotFoundError` | No `account` was provided and the client has no account. |
| `ContractError.ContractFunctionExecutionError` | The `approve` call could not be executed. |
