-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add parallel transactions documentation
Co-Authored-By: Kristof Gazso <[email protected]>
- Loading branch information
1 parent
98fa301
commit f36e4f7
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Sending Multiple Transactions in Parallel | ||
|
||
When working with smart accounts, you can send multiple transactions in parallel by using custom nonce keys. This guide explains how to use this feature effectively. | ||
|
||
## Understanding Nonce Keys | ||
|
||
The EntryPoint contract implements a nonce mechanism that uses a single `uint256` nonce value in the user operation, but treats it as two values: | ||
- `key` (high 192 bits) | ||
- `seq` (low 64 bits) | ||
|
||
This allows you to: | ||
1. Send sequential transactions using the same key (incrementing seq) | ||
2. Send parallel transactions using different keys | ||
|
||
## Sending Multiple Transactions in Parallel | ||
|
||
Here's how to send multiple transactions in parallel: | ||
|
||
```typescript | ||
// First transaction with key 0 | ||
const userOperation1 = await client.buildUserOperation({ | ||
userOperation: { | ||
callData: encodeFunctionData({...}), | ||
}, | ||
}) | ||
|
||
// Second transaction with key 1 | ||
const userOperation2 = await client.buildUserOperation({ | ||
userOperation: { | ||
callData: encodeFunctionData({...}), | ||
nonce: BigInt("0x100000000000000000000000000000000000000000000000000"), // key = 1 | ||
}, | ||
}) | ||
|
||
// Send both transactions | ||
await Promise.all([ | ||
client.sendUserOperation({ userOperation: userOperation1 }), | ||
client.sendUserOperation({ userOperation: userOperation2 }), | ||
]) | ||
``` | ||
|
||
## Important Considerations | ||
|
||
1. Each key maintains its own sequence counter | ||
2. Transactions with different keys can be processed in any order | ||
3. Transactions with the same key must be processed sequentially | ||
4. Keys must be less than 2^192 | ||
|
||
## Best Practices | ||
|
||
1. Use key 0 for regular sequential transactions | ||
2. Use different keys for independent transaction batches | ||
3. Keep track of used keys to avoid conflicts | ||
4. Consider gas costs when sending parallel transactions | ||
|
||
## Error Handling | ||
|
||
If you encounter nonce-related errors: | ||
- Check if you're reusing a nonce that has already been used | ||
- Verify the nonce is formatted correctly | ||
- Ensure you're not using a nonce too far in the future (more than 10 higher than the current nonce) | ||
|
||
For more details on nonce-related errors, see the [AA25 Invalid Nonce](/permissionless/bundler/entrypoint-errors/aa25) error documentation. |