ERC-4337
How to use ERC-4337 to execute cross-chain transactions
One can use ERC-4337 user operations to execute cross-chain transactions. There are three possible interactions that one can have:
- Relaying only on the origin chain
- Relaying only on the destination chain
- Relaying on both the origin and destination chain
Relaying only on the origin chain
Interacting with the solver using ERC-4337 user operations requires two additional steps on top of the standard /quote
flow.
-
The first requires sending an extra field in the
/quote
request body,userOperationGasOverhead
. This field indicates how much additional gas overhead will be necessary to include the user operation on the chain as compared to a normal EOA transaction. -
The second step is optional, you can choose to send the user operation to the Solver’s
eth_sendUserOperation
JSON RPC endpoint or submit it to any Bundler of your choice. Once the user operation has been included on the chain either by the Solver or by another Bundler on the origin chain, the Solver will execute the destination chain transaction.
One slightly different thing in the way the Solver accepts user operations is that the maxFeePerGas
and maxPriorityFeePerGas
should be set to 0. This is done to make sure that the solver does not get paid twice (once by the funds being moved in the call data and second by the on-chain compensation to the Bundler by the Entry Point). This also requires you to use a paymaster as the entry point logic does not allow such a user operation if a smart account has to pay for the operation.
If using an external Bundler, you might need to send non-zero maxFeePerGas
and maxPriorityFeePerGas
as two different parties are being paid in this case.
In the following example, we demonstrate how to use a Safe Smart Account with a Pimlico Paymaster and use Relay to get the quotes and submit the user operation.
The script makes use of Viem’s privateKeyToAccount
to create an owner but any other owner creation method is applicable.
Relaying only on the destination chain
To execute user operations on the destinations, you can pass in the transaction details in the txs array while calling the quote API.
Once the txs array has been created, pass it in the quote API call.
Relaying on both the origin and destination chain
The ability to execute user operations on both the origin and destination chains can be done by individually following the above-mentioned steps.
- Pass the userOperationGasOverhead while making the
/quote
call and also pass the destination chain Entry Point transaction encoded in thetxs
array. - Create the user operation using the transaction data returned in the response of the quote API.
- Execute the origin chain user operation either by making a call to
eth_sendUserOperation
JSON RPC to the Solver or to any other Bundler. - After the user operation is included on the origin chain, the Solver will pick up the transaction and destination
txs
will be executed by the Solver