Combine multiple actions into a single user operation, or run independent operations in parallel using 2D nonces.
A user operation can carry one call or many. Batching packs several calls into
one operation that the smart account executes atomically. Parallelism uses 2D
nonces to submit independent operations concurrently so a slow one doesn’t block
the others. These are two independent patterns, applicable on their own or
together.The examples below use the smartAccount and bundlerClient returned by
Create a modular wallet.
Pass multiple calls to sendUserOperation. The user signs once and the smart
account executes the entire array atomically. A common pattern is to bundle an
ERC-20 approve with the call that spends the allowance, so the user never has
a granted-but-unused approval sitting onchain.
Externally owned accounts process transactions sequentially because each one
consumes the next integer nonce. Smart accounts use 2D nonces, a nonceKey plus
a nonce value. Operations with different nonceKey values are independent and
can land in any order, so a slow operation doesn’t block a fast one.Use parallel execution when:
The user operations don’t depend on each other’s state.
You want to submit multiple operations without waiting for each receipt.
The operations are safe to land in any order.
For sequential dependencies (for example, swap A to B then swap B to C), keep
the default linear nonce by omitting nonceKey or passing 0.
To submit operations in parallel, sign each with a distinct nonceKey greater
than 0, then send them concurrently. Don’t await each receipt before
sending the next, or you lose the benefit.
// Each partial user operation specifies the calls it carries. Build the// array however your app produces them.type PartialUserOperation = Parameters< typeof bundlerClient.sendUserOperation>[0];const userOps: PartialUserOperation[] = [ { calls: [{ to: "0x...", data: "0x..." }], }, { calls: [{ to: "0x...", data: "0x..." }], },];// Sign every user op first. Each gets a distinct nonceKey so they're// independent.const signedUserOps = await Promise.all( userOps.map(async (userOp, index) => { const nonce = await smartAccount.getNonce({ key: BigInt(index + 1) }); const signature = await smartAccount.signUserOperation({ ...userOp, nonce, }); return { ...userOp, nonce, signature }; }),);// Submit the signed ops concurrently. Don't await each receipt before// sending the next one.const hashes = await Promise.all( signedUserOps.map((userOp) => bundlerClient.sendUserOperation({ smartAccount, ...userOp }), ),);
Task { var signedUserOps: [UserOperationV07] = [] for (index, userOp) in userOps.enumerated() { do { let nonceKey = userOp.nonce ?? BigInt(index + 1) let nonce = try await smartAccount.getNonce(key: nonceKey) var signedUserOp = userOp signedUserOp.nonce = nonce signedUserOp.signature = try await smartAccount.signUserOperation( chainId: smartAccount.client.chain.chainId, userOp: signedUserOp ) signedUserOps.append(signedUserOp) } catch { print("Error signing user operation: \(error)") } } await withTaskGroup(of: Void.self) { group in for userOp in signedUserOps { group.addTask { do { let sendResult = try await bundlerClient.sendUserOperation( account: smartAccount, calls: nil, partialUserOp: userOp ) print(sendResult) } catch { print("Error sending user operation: \(error)") } } } }}
val signedUserOps = mutableListOf<UserOperationV07>()userOps.forEachIndexed { index, userOp -> CoroutineScope(Dispatchers.IO).launch { try { val chain = ArcTestnet val nonceKey = userOp.nonce ?: BigInteger("${index + 1}") val nonce = smartAccount.getNonce(key = nonceKey) val signature = smartAccount.signUserOperation( context, chain.chainId, userOp.copy(nonce = nonce), ) signedUserOps.add(userOp.copy(nonce = nonce, signature = signature)) } catch (error: Exception) { Log.e(TAG, "Error signing user operation at index $index: ${error.message}") } }}CoroutineScope(Dispatchers.IO).launch { val sendOperations = signedUserOps.map { userOp -> async { try { bundlerClient.sendUserOperation( context, smartAccount, calls = null, partialUserOp = userOp, ) } catch (error: Exception) { Log.e(TAG, "Error sending user operation: ${error.message}") } } } sendOperations.awaitAll()}
List<UserOperationV07> signedUserOps = new ArrayList<>();for (int i = 0; i < userOps.size(); i++) { try { UserOperationV07 userOp = userOps.get(i); BigInteger nonceKey = userOp.getNonce() == null ? BigInteger.valueOf(i + 1) : userOp.getNonce(); CompletableFuture<BigInteger> nonceFuture = new CompletableFuture<>(); smartAccount.getNonce(nonceKey, new CustomContinuation<>(nonceFuture)); BigInteger nonce = nonceFuture.join(); userOp.setNonce(nonce); CompletableFuture<String> signatureFuture = new CompletableFuture<>(); smartAccount.signUserOperation( context, ArcTestnet.INSTANCE.getChainId(), userOp, new CustomContinuation<>(signatureFuture) ); userOp.setSignature(signatureFuture.join()); signedUserOps.add(userOp); } catch (Exception error) { Log.e(TAG, "Error signing user operation at index " + i + ": " + error.getMessage()); }}List<CompletableFuture<String>> sendOperations = signedUserOps.stream() .map(userOp -> { CompletableFuture<String> userOpHashFuture = new CompletableFuture<>(); try { bundlerClient.sendUserOperation( context, smartAccount, null, // calls userOp, // partialUserOp new Paymaster.True(), new CustomContinuation<>(userOpHashFuture) ); } catch (Exception e) { userOpHashFuture.completeExceptionally(e); } return userOpHashFuture; }) .collect(Collectors.toList());CompletableFuture.allOf(sendOperations.toArray(new CompletableFuture[0])).join();