Skip to content

Commit

Permalink
feat: add parallel transactions documentation
Browse files Browse the repository at this point in the history
Co-Authored-By: Kristof Gazso <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and kristofgazso committed Dec 30, 2024
1 parent 98fa301 commit f36e4f7
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions docs/pages/permissionless/parallel-transactions.mdx
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.

0 comments on commit f36e4f7

Please sign in to comment.