Skip to content

Commit 9d9a477

Browse files
committed
add draft examples
1 parent 8e9c015 commit 9d9a477

File tree

2 files changed

+141
-8
lines changed

2 files changed

+141
-8
lines changed

wallet/how-to/send-transactions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ You can send a transaction in MetaMask using the
1212
RPC method.
1313

1414
:::note
15-
To [send atomic batch transactions](send-batch-transactions.md), use `wallet_sendCalls`.
15+
To [send batch transactions](send-batch-transactions.md), use `wallet_sendCalls`.
1616
:::
1717

1818
For example, the following JavaScript gets the user's accounts and sends a transaction when they

wallet/how-to/send-transactions/send-batch-transactions.md

Lines changed: 140 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,163 @@
22
description: Send atomic batch transactions using wallet_sendCalls.
33
---
44

5-
# Send atomic batch transactions
5+
# Send batch transactions
66

7-
You can send and manage atomic batch transactions in MetaMask, using the methods specified by
7+
You can send and manage batch transactions in MetaMask, using the methods specified by
88
[EIP-5792](https://eips.ethereum.org/EIPS/eip-5792):
99

1010
- `wallet_getCapabilities` - Query whether support for atomic batch transactions is available.
11-
- `wallet_sendCalls` - Submit multiple transactions to be processed atomically as one by the wallet.
11+
- `wallet_sendCalls` - Submit multiple transactions to be processed atomically or sequentially by the wallet.
1212
- `wallet_getCallsStatus` - Track the status of your transaction batch.
1313

14-
The key benefits of atomic batch transactions include:
14+
The key benefits of batch transactions include:
1515

1616
- **Fewer clicks and less friction** - Users only need to review and approve a single wallet confirmation, instead of multiple confirmations.
17-
- **Faster completion times** - Only a single atomic batch transaction must be confirmed onchain, instead of multiple individual transactions.
17+
- **Faster completion times** - With [EIP-7702](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7702.md),
18+
only a single atomic transaction is confirmed onchain, instead of multiple individual transactions.
1819

1920
## Steps
2021

2122
### 1. Query whether the wallet supports atomic batch
2223

23-
:::warning Important
24+
Use `wallet_getCapabilities` to query whether the wallet supports atomic batch transactions.
25+
For example:
26+
27+
```js title="index.js"
28+
const result = await provider // Or window.ethereum if you don't support EIP-6963.
29+
.request({
30+
"method": "wallet_getCapabilities",
31+
"params": [
32+
"0xd46e8dd67c5d32be8058bb8eb970870f07244567", // The user's wallet address.
33+
["0x2105", "0x14A34"] // (Optional) A list of chain IDs to query for.
34+
],
35+
});
36+
```
37+
38+
This method returns whether the `atomic` capability is supported for each chain ID:
39+
40+
```json
41+
{
42+
"0x2105": {
43+
"atomic": {
44+
"supported": true
45+
}
46+
},
47+
"0x14A34": {
48+
"atomic": {
49+
"supported": false
50+
}
51+
}
52+
}
53+
```
54+
55+
:::note
2456
If atomic batch is not supported, fall back to [`eth_sendTransaction`](index.md) instead of `wallet_sendCalls`,
2557
and [`eth_getTransactionReceipt`](/wallet/reference/json-rpc-methods/eth_gettransactionreceipt)
2658
instead of `wallet_getCallsStatus`.
2759
:::
2860

2961
### 2. Submit a batch of transactions
3062

31-
### 3. Track the status of the batch of transactions
63+
Use `wallet_sendCalls` to submit a batch of transactions.
64+
Set `atomicRequired` to:
65+
66+
- `true` if you require MetaMask to execute the calls atomically.
67+
Make sure atomic batch is supported first, via
68+
[`wallet_getCapabilities`](#1-query-whether-the-wallet-supports-atomic-batch).
69+
- `false` if the calls can be executed either sequentially or atomically.
70+
71+
For example:
72+
73+
```js title="index.js"
74+
const result = await provider.
75+
request({
76+
"method": "wallet_sendCalls", // Or window.ethereum if you don't support EIP-6963.
77+
"params": [
78+
{
79+
version: "1.0",
80+
from: "0xd46e8dd67c5d32be8058bb8eb970870f07244567", // The sender's address.
81+
chainId: "0x2105", // The chain ID, which must match the currently selected network.
82+
atomicRequired: true, // Whether or not atomicity is required.
83+
calls: [ // The list of calls to send as a batch.
84+
{
85+
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
86+
value: "0x9184e72a",
87+
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
88+
},
89+
{
90+
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
91+
value: "0x182183",
92+
data: "0xfbadbaf01"
93+
}
94+
]
95+
}
96+
],
97+
});
98+
```
99+
100+
This method returns a batch ID that you can use to track the status of the batch:
101+
102+
```json
103+
{
104+
"id": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
105+
}
106+
```
107+
108+
### 3. Track the status of the batch of transactions
109+
110+
Use `wallet_getCallsStatus` to track the status of the submitted batch of transactions,
111+
using the batch ID returned by `wallet_sendCalls`.
112+
For example:
113+
114+
```js title="index.js"
115+
const result = await provider // Or window.ethereum if you don't support EIP-6963.
116+
.request({
117+
"method": "wallet_getCallsStatus",
118+
"params": [
119+
"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331" // Batch ID.
120+
],
121+
});
122+
```
123+
124+
This method returns status information about the batch of transactions, including:
125+
126+
- The status code of the batch.
127+
- Whether the batch was executed atomically.
128+
- A list of transaction receipts.
129+
130+
```json
131+
{
132+
"version": "1.0",
133+
"chainId": "0x2105",
134+
"id": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
135+
"status": 200, // Status code. 200 means confirmed.
136+
"atomic": true, // Whether the calls were executed atomically.
137+
"receipts": [ // List of transaction receipts.
138+
{
139+
"logs": [
140+
{
141+
"address": "0xa922b54716264130634d6ff183747a8ead91a40b",
142+
"topics": [
143+
"0x5a2a90727cc9d000dd060b1132a5c977c9702bb3a52afe360c9c22f0e9451a68"
144+
],
145+
"data": "0xabcd"
146+
}
147+
],
148+
"status": "0x1",
149+
"blockHash": "0xf19bbafd9fd0124ec110b848e8de4ab4f62bf60c189524e54213285e7f540d4a",
150+
"blockNumber": "0xabcd",
151+
"gasUsed": "0xdef",
152+
"transactionHash": "0x9b7bb827c2e5e3c1a0a44dc53e573aa0b3af3bd1f9f5ed03071b100bb039eaff"
153+
}
154+
]
155+
}
156+
```
157+
158+
:::note
159+
If the calls were executed atomically in a single transaction, a single receipt is returned.
160+
161+
In some cases, calls can be executed atomically but in multiple transactions (for example, using
162+
`eth_bundle` on an L2 network resistant to reorgs).
163+
In these cases, `atomic` is `true` but multiple receipts are returned.
164+
:::

0 commit comments

Comments
 (0)