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/shy-adults-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

**Experimental:** Added `forceAtomic` and `id` parameters to `sendCalls`
48 changes: 48 additions & 0 deletions .changeset/ten-pets-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
"viem": minor
---

**Breaking (Experimental):** Updated EIP-5792 to the latest spec changes. The following APIs have been updated:

#### `getCallsStatus`

```diff
const result = await client.getCallsStatus({ id })
// ^?
{
+ atomic: boolean
+ chainId: number
+ id: string
receipts: Receipt[]
- status: 'PENDING' | 'CONFIRMED'
+ status: 'pending' | 'success' | 'failure' | undefined
+ statusCode: number
+ version: string
}
```

#### `sendCalls`

```diff
const result = await client.sendCalls({ calls })
// ^?
- string
+ { id: string, capabilities?: Capabilities }
```

#### `waitForCallsStatus`

```diff
const result = await client.waitForCallsStatus({ id })
// ^?
{
+ atomic: boolean
+ chainId: number
+ id: string
receipts: Receipt[]
- status: 'PENDING' | 'CONFIRMED'
+ status: 'pending' | 'success' | 'failure' | undefined
+ statusCode: number
+ version: string
}
```
18 changes: 13 additions & 5 deletions site/pages/experimental/eip5792/getCallsStatus.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
description: Returns the status and receipts of a call batch.
description: Returns the status of a call batch.
---

# getCallsStatus

Returns the status and receipts of a call batch that was sent via `sendCalls`.
Returns the status of a call batch that was sent via `sendCalls`.

[Read more.](https://github.com/ethereum/EIPs/blob/1663ea2e7a683285f977eda51c32cec86553f585/EIPS/eip-5792.md#wallet_getcallsstatus)
[Read more.](https://eips.ethereum.org/EIPS/eip-5792#wallet_getcallsstatus)

:::warning[Warning]
This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production.
Expand All @@ -19,9 +19,17 @@ This is an experimental action that is not supported in most wallets. It is reco
```ts twoslash [example.ts]
import { walletClient } from './config'

const { status, receipts } = await walletClient.getCallsStatus({ // [!code focus:99]
const result = await walletClient.getCallsStatus({ // [!code focus:99]
id: '0x1234567890abcdef',
})
// @log: {
// @log: atomic: false,
// @log: chainId: 1,
// @log: id: '0x1234567890abcdef',
// @log: statusCode: 200,
// @log: status: 'success',
// @log: receipts: [{ ... }],
// @log: }
```

```ts twoslash [config.ts] filename="config.ts"
Expand All @@ -45,7 +53,7 @@ export const [account] = await walletClient.getAddresses()

`WalletGetCallsStatusReturnType`

Status and receipts of the calls.
Status of the calls.

## Parameters

Expand Down
15 changes: 15 additions & 0 deletions site/pages/experimental/eip5792/getCapabilities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,19 @@ import { walletClient } from './config'
const capabilities = await walletClient.getCapabilities({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code focus]
})
```

### chainId

- **Type:** `number`

The chain ID to get capabilities for.

```ts twoslash [example.ts]
import { walletClient } from './config'
// ---cut---
const capabilities = await walletClient.getCapabilities({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
chainId: 8453, // [!code focus]
})
```
77 changes: 63 additions & 14 deletions site/pages/experimental/eip5792/sendCalls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ description: Sign and broadcast a batch of calls to the network.

# sendCalls

Requests for the wallet to sign and broadcast a batch of calls (transactions) to the network.
Requests for the wallet to sign and broadcast a batch of calls to the network.

[Read more.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls)
[Read more.](https://eips.ethereum.org/EIPS/eip-5792#wallet_sendcalls)

:::warning[Warning]
This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production.
Expand All @@ -20,7 +20,7 @@ This is an experimental action that is not supported in most wallets. It is reco
import { parseEther } from 'viem'
import { account, walletClient } from './config'

const id = await walletClient.sendCalls({ // [!code focus:99]
const { id } = await walletClient.sendCalls({ // [!code focus:99]
account,
calls: [
{
Expand Down Expand Up @@ -56,7 +56,7 @@ Notes:

- `account` and `chain` are top level properties as all calls should be sent by the same account and chain.
- Properties of `calls` items are only those shared by all transaction types (e.g. `data`, `to`, `value`). The Wallet should handle other required properties like gas & fees.
- [Read `wallet_sendCalls` on EIP-5792.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls)
- [Read `wallet_sendCalls` on EIP-5792.](https://eips.ethereum.org/EIPS/eip-5792#wallet_sendcalls)

### Account Hoisting

Expand All @@ -69,7 +69,7 @@ If you do not wish to pass an `account` to every `sendCalls`, you can also hoist
```ts twoslash [example.ts]
import { walletClient } from './config'

const id = await walletClient.sendCalls({ // [!code focus:99]
const { id } = await walletClient.sendCalls({ // [!code focus:99]
calls: [
{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
Expand Down Expand Up @@ -116,7 +116,7 @@ const abi = parseAbi([
'function transferFrom(address, address, uint256) returns (bool)',
])

const id = await walletClient.sendCalls({ // [!code focus:99]
const { id } = await walletClient.sendCalls({ // [!code focus:99]
calls: [
{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
Expand Down Expand Up @@ -179,7 +179,7 @@ export const walletClient = createWalletClient({

## Returns

`string`
`{ id: string, capabilities?: WalletCapabilities }`

The identifier can be any arbitrary string. The only requirement is that for a given session, consumers should be able to call `getCallsStatus` with this identifier to retrieve a batch call status and call receipts.

Expand All @@ -196,7 +196,7 @@ Accepts a [JSON-RPC Account](/docs/clients/wallet#json-rpc-accounts).
```ts twoslash
import { walletClient } from './config'

const id = await walletClient.sendCalls({
const { id } = await walletClient.sendCalls({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code focus]
calls: [
{
Expand All @@ -222,7 +222,7 @@ The target chain to broadcast the calls.
import { mainnet } from 'viem/chains'
import { walletClient } from './config'

const id = await walletClient.sendCalls({
const { id } = await walletClient.sendCalls({
chain: mainnet, // [!code focus]
calls: [
{
Expand All @@ -247,7 +247,7 @@ An array of calls to be signed and broadcasted.
import { mainnet } from 'viem/chains'
import { walletClient } from './config'

const id = await walletClient.sendCalls({
const { id } = await walletClient.sendCalls({
chain: mainnet,
calls: [ // [!code focus]
{ // [!code focus]
Expand All @@ -272,7 +272,7 @@ Calldata to broadcast (typically a contract function selector with encoded argum
import { mainnet } from 'viem/chains'
import { walletClient } from './config'

const id = await walletClient.sendCalls({
const { id } = await walletClient.sendCalls({
chain: mainnet,
calls: [
{
Expand All @@ -297,7 +297,7 @@ Recipient address of the call.
import { mainnet } from 'viem/chains'
import { walletClient } from './config'

const id = await walletClient.sendCalls({
const { id } = await walletClient.sendCalls({
chain: mainnet,
calls: [
{
Expand All @@ -322,7 +322,7 @@ Value to send with the call.
import { mainnet } from 'viem/chains'
import { walletClient } from './config'

const id = await walletClient.sendCalls({
const { id } = await walletClient.sendCalls({
chain: mainnet,
calls: [
{
Expand All @@ -346,7 +346,7 @@ Capability metadata for the calls (e.g. specifying a paymaster).
```ts twoslash
import { walletClient } from './config'

const id = await walletClient.sendCalls({
const { id } = await walletClient.sendCalls({
calls: [
{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
Expand All @@ -364,3 +364,52 @@ const id = await walletClient.sendCalls({
} // [!code focus]
})
```

### forceAtomic

- **Type:** `boolean`
- **Default:** `false`

Force the calls to be executed atomically. [See more](https://eips.ethereum.org/EIPS/eip-5792#call-execution-atomicity)

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

const { id } = await walletClient.sendCalls({
calls: [
{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
},
{
data: '0xdeadbeef',
to: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
},
],
forceAtomic: true, // [!code focus]
})
```

### id

- **Type:** `string`

Attribute the call batch with an identifier.

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

const { id } = await walletClient.sendCalls({
calls: [
{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
},
{
data: '0xdeadbeef',
to: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
},
],
id: '<my-batch-id>', // [!code focus]
})
```
36 changes: 29 additions & 7 deletions site/pages/experimental/eip5792/waitForCallsStatus.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
description: Waits for a call bundle to be confirmed & included on a Block.
description: Waits for a call batch to be confirmed & included on a Block.
---

# waitForCallsStatus

Waits for a call bundle to be confirmed & included on a [Block](/docs/glossary/terms#block) before returning the status & receipts.
Waits for a call batch to be confirmed & included on a [Block](/docs/glossary/terms#block) before returning the status & receipts.

:::warning[Warning]
This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production.
Expand All @@ -18,17 +18,25 @@ This is an experimental action that is not supported in most wallets. It is reco
import { parseEther } from 'viem'
import { account, walletClient } from './config'

const id = await walletClient.sendCalls({
const { id } = await walletClient.sendCalls({
account,
calls: [{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
}],
})

const { status, receipts } = await walletClient.waitForCallsStatus({ // [!code focus]
const result = await walletClient.waitForCallsStatus({ // [!code focus]
id, // [!code focus]
}) // [!code focus]
// @log: {
// @log: atomic: false,
// @log: chainId: 1,
// @log: id: '0x1234567890abcdef',
// @log: statusCode: 200,
// @log: status: 'success',
// @log: receipts: [{ ... }],
// @log: }
```

```ts twoslash [config.ts] filename="config.ts"
Expand Down Expand Up @@ -63,7 +71,7 @@ Status and receipts of the calls.
Identifier of the call batch.

```ts
const { status, receipts } = await walletClient.waitForCallsStatus({
const result = await walletClient.waitForCallsStatus({
id: '0xdeadbeef', // [!code focus]
})
```
Expand All @@ -76,12 +84,26 @@ const { status, receipts } = await walletClient.waitForCallsStatus({
Polling interval in milliseconds.

```ts
const { status, receipts } = await walletClient.waitForCallsStatus({
const result = await walletClient.waitForCallsStatus({
id: '0xdeadbeef',
pollingInterval: 1_000, // [!code focus]
})
```

### status

- **Type:** `(parameters: { statusCode: number, status: string | undefined }) => boolean`
- **Default:** `(parameters) => parameters.statusCode >= 200`

Status to wait for. Defaults to non-pending status codes (`>=200`).

```ts
const result = await walletClient.waitForCallsStatus({
id: '0xdeadbeef',
status: ({ status }) => status === 'success', // [!code focus]
})
```

### timeout

- **Type:** `number`
Expand All @@ -90,7 +112,7 @@ const { status, receipts } = await walletClient.waitForCallsStatus({
Timeout in milliseconds before `waitForCallsStatus` stops polling.

```ts
const { status, receipts } = await walletClient.waitForCallsStatus({
const result = await walletClient.waitForCallsStatus({
id: '0xdeadbeef',
timeout: 10_000, // [!code focus]
})
Expand Down
Loading
Loading