This example shows one common use case: sending multiple ERC-20 tokens in the same action using a builder’s executeBatch method.
As with other examples, you will import ethers and userop.
Userop.js uses a builder pattern for creating user operations. Rather than create a user operation completely from scratch, we can use one of the presets. In this example we’ll use the simpleAccount preset, which is configured to match the simpleAccount example from the Ethereum Foundation.
This initializes a simpleAccount user operation builder. This preset includes an executeBatch function, which can be used to execute multiple transactions.
We will assume that you have a list of recipients, the tokens you are sending, and the amount of the tokens each will receive.
We will loop through the list of recipients and put the transaction data into a data array. Each element of the data array will be encoded function data that will be executed by the smart account.
Then simply create and send the user operation:
You can view an example ERC-20 token transfer in the ERC-4337 Example Repository.