> **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.

# Get Assets \[wallet.getAssets]

Retrieves an account's native currency, ERC-20 tokens, and ERC-721 tokens from the connected wallet
through [ERC-7811 `wallet_getAssets`](https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7811.md).

Assets are keyed by chain ID. By default, assets are also aggregated across chains under the `0` key.

## Usage

This example retrieves the assets held by an account.

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

const assets = await client.wallet.getAssets()
// @log: {
// @log:   0: [{ balance: 32000000000n, chainIds: [1, 8453], metadata: { ... }, type: 'erc20', ... }],
// @log:   1: [{ balance: 12000000000n, metadata: { ... }, type: 'erc20', ... }],
// @log:   8453: [{ balance: 20000000000n, metadata: { ... }, type: 'erc20', ... }],
// @log: }
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, custom, walletActions } from 'viem'
import 'viem/window'

export const client = Client.create({
  account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  transport: custom(window.ethereum!),
}).extend(walletActions())
```
:::

### Standalone Action

Call `Actions.wallet.getAssets` directly by passing the Client as the first argument.

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

const assets = await Actions.wallet.getAssets(client)
// @log: {
// @log:   0: [{ balance: 32000000000n, chainIds: [1, 8453], metadata: { ... }, type: 'erc20', ... }],
// @log:   1: [{ balance: 12000000000n, metadata: { ... }, type: 'erc20', ... }],
// @log:   8453: [{ balance: 20000000000n, metadata: { ... }, type: 'erc20', ... }],
// @log: }
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, custom } from 'viem'
import 'viem/window'

export const client = Client.create({
  account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  transport: custom(window.ethereum!),
})
```
:::

## Recipes

### Filter by Asset Type and Chain

Use `assetTypes` and `chainIds` to request only the asset categories and networks that your
interface displays.

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

const assets = await client.wallet.getAssets({
  assetTypes: ['native', 'erc20'], // [!code focus]
  chainIds: [mainnet.id, base.id], // [!code focus]
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, custom, walletActions } from 'viem'
import 'viem/window'

export const client = Client.create({
  account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  transport: custom(window.ethereum!),
}).extend(walletActions())
```
:::

### Aggregate Tokens by Symbol

Provide an aggregation function when the same token has different contract addresses across
chains. This example groups ERC-20 balances by symbol under the `0` key.

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

const assets = await client.wallet.getAssets({
  aggregate: (asset) => // [!code focus]
    asset.type === 'erc20' // [!code focus]
      ? asset.metadata.symbol // [!code focus]
      : (asset.address ?? 'native'), // [!code focus]
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, custom, walletActions } from 'viem'
import 'viem/window'

export const client = Client.create({
  account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  transport: custom(window.ethereum!),
}).extend(walletActions())
```
:::

## Return Value

`{ [chainId: number]: readonly Asset[] }`

The account's assets, keyed by chain ID.
Each asset includes its `balance`, `type`, type-specific `metadata`, and an `address` for non-native
assets.

The `type` is `'native'`, `'erc20'`, `'erc721'`, or `{ custom: string }`.

Unless [`aggregate`](#aggregate) is disabled, the `0` key contains assets aggregated across chains.
Each aggregated asset includes its source `chainIds`.

## Parameters

### account

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

The Account (or address) to fetch assets for.

```ts twoslash
import { Actions } from 'viem'
// [!include ~/snippets/docs/reference-client.ts:setup]
// ---cut---
const assets = await Actions.wallet.getAssets(client, {
  account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', // [!code focus]
})
```

### aggregate

* **Type:** `boolean | ((asset: Asset) => string)`
* **Default:** `true`

Whether to aggregate assets across chains under the `0` key.
Assets are aggregated by contract address by default.

Provide a function to derive a custom key for each asset.
Set `aggregate` to `false` to disable aggregation.

```ts twoslash
import { Actions } from 'viem'
// [!include ~/snippets/docs/reference-client.ts:setup]
// ---cut---
const assets = await Actions.wallet.getAssets(client, {
  aggregate: false, // [!code focus]
})
```

### assets

* **Type:** `{ [chainId: number]: readonly { address: Address | 'native'; type: string }[] }`

Filter the response to specific assets per chain.

```ts twoslash
import { Actions } from 'viem'
// [!include ~/snippets/docs/reference-client.ts:setup]
// ---cut---
const assets = await Actions.wallet.getAssets(client, {
  assets: { // [!code focus]
    1: [ // [!code focus]
      { // [!code focus]
        address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // [!code focus]
        type: 'erc20', // [!code focus]
      }, // [!code focus]
    ], // [!code focus]
  }, // [!code focus]
})
```

### assetTypes

* **Type:** `readonly ('native' | 'erc20' | 'erc721' | string)[]`

Filter the response to specific asset types.

```ts twoslash
import { Actions } from 'viem'
// [!include ~/snippets/docs/reference-client.ts:setup]
// ---cut---
const assets = await Actions.wallet.getAssets(client, {
  assetTypes: ['native', 'erc20'], // [!code focus]
})
```

### chainIds

* **Type:** `readonly number[]`

Filter the response to specific chains.

```ts twoslash
import { Actions } from 'viem'
// [!include ~/snippets/docs/reference-client.ts:setup]
// ---cut---
const assets = await Actions.wallet.getAssets(client, {
  chainIds: [1, 8453], // [!code focus]
})
```

## Errors

| Error | Description |
| --- | --- |
| `Account.NotFoundError` | No `account` was provided and the client has no default account. |
