Send parallel transactions

This quide explains how to send multiple parallel transactions. Note that you don’t need to send parallel transactions for batching calls. This is for sending new transactions when, for example, there’s already a transaction in the mempool for a certain account.

Prerequisites

The nonceKey override must fit into a uint152!
Required SDK version: ^v4.61.0

Use the useSendCalls hook and the nonceOverride capability parameter to send parallel userops. You can also use the usePrepareCalls hook to only prepare the operation for signing.

You’ll need both ALCHEMY_API_KEY and ALCHEMY_POLICY_ID environment variables set to follow along!

1import { config } from "@/app/config";
2import {
3 useSendCalls,
4 useSmartAccountClient,
5 useSmartWalletClient,
6} from "@account-kit/react";
7
8export default function SendParallelCalls() {
9 const { client } = useSmartAccountClient({});
10 const { sendCallsAsync } = useSendCalls({ client });
11 const walletClient = useSmartWalletClient({
12 account: client?.account.address,
13 });
14
15 const handleSend = async () => {
16 if (!client) {
17 throw new Error("Smart account client not connected");
18 }
19 if (!walletClient) {
20 throw new Error("Smart wallet client not connected");
21 }
22
23 try {
24 const [{ ids: idsOne }, { ids: idsTwo }] = await Promise.all([
25 sendCallsAsync({
26 capabilities: {
27 paymasterService: {
28 policyId: config.policyId,
29 },
30 nonceOverride: {
31 nonceKey: "0x01",
32 },
33 },
34 calls: [
35 {
36 to: "0x0000000000000000000000000000000000000000",
37 value: "0x00",
38 data: "0x",
39 },
40 ],
41 }),
42 sendCallsAsync({
43 capabilities: {
44 paymasterService: {
45 policyId: config.policyId,
46 },
47 nonceOverride: {
48 nonceKey: "0x02",
49 },
50 },
51 calls: [
52 {
53 to: "0x0000000000000000000000000000000000000000",
54 value: "0x00",
55 data: "0x",
56 },
57 ],
58 }),
59 ]);
60
61 console.log("id of sent call one: ", idsOne);
62 console.log("id of sent call two: ", idsTwo);
63
64 const result = await Promise.all([
65 walletClient.waitForCallsStatus({ id: idsOne[0]! }),
66 walletClient.waitForCallsStatus({ id: idsTwo[0]! }),
67 ]);
68
69 console.log(result);
70 } catch (error) {
71 console.error(error);
72 }
73 };
74 return <button onClick={handleSend}>Click to Send</button>;
75}