Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gorgeous-queens-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

**Experimental:** Added support for ERC-7811 `getAssets`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"src": {
"entry": [
"index.ts!",
"{account-abstraction,accounts,actions,celo,chains,ens,experimental,experimental/erc7739,experimental/erc7821,experimental/erc7846,experimental/erc7895,linea,node,nonce,op-stack,siwe,utils,window,zksync}/index.ts!",
"{account-abstraction,accounts,actions,celo,chains,ens,experimental,experimental/erc7739,experimental/erc7821,experimental/erc7811,experimental/erc7846,experimental/erc7895,linea,node,nonce,op-stack,siwe,utils,window,zksync}/index.ts!",
"chains/utils.ts!"
],
"ignore": ["node/trustedSetups_cjs.ts"]
Expand Down
18 changes: 18 additions & 0 deletions site/pages/experimental/erc7811/client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Extending Client with ERC-7811 Actions [Setting up your Viem Client]

To use the experimental functionality of [ERC-7811](https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7811.md), you can extend your existing (or new) Viem Client with experimental [ERC-7811](https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7811.md) Actions.

```ts
import { createClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { erc7811Actions } from 'viem/experimental' // [!code focus]

const client = createClient({
chain: mainnet,
transport: http(),
}).extend(erc7811Actions()) // [!code focus]

const assets = await client.getAssets({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
})
```
114 changes: 114 additions & 0 deletions site/pages/experimental/erc7811/getAssets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
description: Requests to get assets for an account from a Wallet.
---

# getAssets

Requests to get assets for an account from a Wallet.

## Usage

:::code-group

```ts twoslash [example.ts]
import { walletClient } from './config'

const assets = await walletClient.getAssets({ // [!code focus]
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code focus]
}) // [!code focus]
```

```ts twoslash [config.ts] filename="config.ts"
import 'viem/window'
// ---cut---
import { createWalletClient, custom } from 'viem'
import { erc7811Actions } from 'viem/experimental'

export const walletClient = createWalletClient({
transport: custom(window.ethereum!),
}).extend(erc7811Actions())
```

:::

## Returns

List of assets for the given account.

```ts
type ReturnType = {
[chainId: number]: readonly {
address: Address | 'native'
balance: Hex
metadata?: unknown | undefined
type: 'native' | 'erc20' | 'erc721' | (string & {})
}[]
}
```

## Parameters

### `account`

- **Type:** `Account | Address`

The account to get assets for.

```ts
import { walletClient } from './config'

const assets = await walletClient.getAssets({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code focus]
})
```

### `assets`

- **Type:** `{ [chainId: number]: readonly { address: Address | 'native', type: 'native' | 'erc20' | 'erc721' | (string & {}) }[] }`

Filter by assets.

```ts
import { walletClient } from './config'

const assets = await walletClient.getAssets({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
assets: { // [!code focus]
8453: [{ address: '0x1234567890abcdef1234567890abcdef12345678', type: 'erc20' }], // [!code focus]
}, // [!code focus]
})
```

### `assetTypes`

- **Type:** `readonly ('native' | 'erc20' | 'erc721' | (string & {}))[]`

Filter by asset types.

```ts
import { walletClient } from './config'

const assets = await walletClient.getAssets({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
assetTypes: ['erc20'], // [!code focus]
})
```

### `chainIds`

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

Filter by chain IDs.

```ts
import { walletClient } from './config'

const assets = await walletClient.getAssets({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
chainIds: [8453], // [!code focus]
})
```

## JSON-RPC Methods

- [`wallet_getAssets`](https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7811.md)
18 changes: 18 additions & 0 deletions site/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,24 @@ export const sidebar = {
},
],
},
{
text: 'ERC-7811',
items: [
{
text: 'Client',
link: '/experimental/erc7811/client',
},
{
text: 'Actions',
items: [
{
text: 'getAssets',
link: '/experimental/erc7811/getAssets',
},
],
},
],
},
{
text: 'ERC-7821',
items: [
Expand Down
Loading
Loading