Skip to content

Commit

Permalink
docs: details about batching user operations (#237)
Browse files Browse the repository at this point in the history
* docs: details about batching user operations

* Update site/guides/batching-transactions.md

Co-authored-by: Ajay Vasisht <[email protected]>

* Update site/guides/batching-transactions.md

Co-authored-by: Ajay Vasisht <[email protected]>

* Update site/guides/batching-transactions.md

Co-authored-by: Ajay Vasisht <[email protected]>

---------

Co-authored-by: Ajay Vasisht <[email protected]>
  • Loading branch information
denniswon and avasisht23 committed Nov 13, 2023
1 parent d7e8460 commit d637c28
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions site/guides/batching-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,28 @@ head:

# How to Submit Batch Transactions

One benefit of Smart Contract Accounts is that it's possible to batch transactions in one User Operation. Not all Smart Contract Accounts support batching. But, if the account you're using does, then implementations of `SmartAccountProvider` will allow you to make those calls.
One benefit of Smart Contract Accounts is that it's possible to batch transactions in one User Operation. Not all Smart Contract Accounts support batching. But, if the `ISmartContractAccount` implementation you're using has the [`encodeBatchExecute`](/packages/aa-core/accounts/optional/encodeBatchExecute.md) method, then implementations of `SmartAccountProvider` will allow you to make those calls.

There are two ways you can batch transactions using `SmartAccountProvider`:

1. via `sendUserOperation`
2. via `sendTransactions`

## `sendUserOperation`
:::tip Note 1: `SimpleSmartContractAccount` and `LightSmartContractAccount`
Both `SimpleSmartContractAccount` and `LightSmartContractAccount` implement `encodeBatchExecute`, thus supports batching `UserOperations` out of the box.
:::

:::tip Note 2: Transactions Batched as a Single User Operation
When you batch transactions, the transaction actions (`target`s and `calldata`s) are batched into a single `UserOperation`, where the sender is the account itself.
:::

:::tip Note 3: Batched Transactions Ordering
The batched `UserOperation` gets executed by the account calling the `executeBatch` method on the [`SimpleAccount`](https://github.com/eth-infinitism/account-abstraction/blob/ver0.6.0/contracts/samples/SimpleAccount.sol) or [`LightAccount`](https://github.com/alchemyplatform/light-account/blob/v1.0.2/src/LightAccount.sol) smart contracts. `executeBatch` processes the input array of transactions data linearly, guaranteeing the execution order of those transactions to be **sequential**.
:::

## Batching using [`sendUserOperation`](/packages/aa-core/provider/sendUserOperation.md)

The `SmartAccountProvider` supports passing either a single `UserOperation` or an array of `UserOperation`s to `sendUserOperation`. If you pass an array, the provider will batch the transactions into a single User Operation and submit it to the network. Let's see an example:
The `SmartAccountProvider` supports passing either a single `UserOperation` or an array of `UserOperation`s to `sendUserOperation`. If you pass an array, the provider will batch the transactions into a single User Operation and submit it to the bundler. Let's see an example:

::: code-group

Expand All @@ -53,7 +65,7 @@ const { hash } = await provider.sendUserOperation([

:::

## `sendTransactions`
## Batching using [`sendTransactions`](/packages/aa-core/provider/sendTransactions.md)

The `SmartAccountProvider` supports sending `UserOperation`s and waiting for them to be mined in a transaction via the `sendTransaction` and `sendTransactions` methods. The latter allows for batching in the same way `sendUserOperation`:

Expand Down

0 comments on commit d637c28

Please sign in to comment.