Account Abstraction (AA) via ERC-4337 is a standard that introduces smart contract-based accounts (also called Smart Accounts or Contract Wallets) in Ethereum. Unlike traditional EOAs (Externally Owned Accounts) that are controlled by private keys, smart accounts allow for programmable and customizable account management. This opens up features like gasless transactions, multi-signature wallets, session keys, and paymasters.
The UserOperation
struct represents a transaction request made by a user. Unlike traditional transactions that are directly submitted by EOAs, UserOperation
encapsulates all the details of the transaction and is submitted to the EntryPoint
contract for processing.
Fields of UserOperation
:
sender
: The Smart Account address initiating the transaction.nonce
: A counter to prevent replay attacks.initCode
: Code used to deploy the Smart Account if it does not exist yet.callData
: Encoded function call to be executed by the Smart Account.callGasLimit
: The gas limit for executing thecallData
.verificationGasLimit
: Gas limit for the validation phase.preVerificationGas
: Gas estimation for the preprocessing of theUserOperation
.maxFeePerGas
andmaxPriorityFeePerGas
: EIP-1559 gas fee fields.paymasterAndData
: Paymaster address and optional data for sponsoring gas fees.signature
: Signature for validating the request.
The EntryPoint
contract is the core of the ERC-4337 standard. It acts as a centralized router that:
- Receives and validates
UserOperation
requests. - Forwards the call to the appropriate Smart Account.
- Manages the gas payment and interacts with paymasters if needed.
Key Functions:
handleOps
: Processes a batch ofUserOperation
s in a single transaction.simulateValidation
: Allows off-chain simulation of UserOperation validation for gas estimation.
Smart Accounts are the programmable accounts that handle user operations. They must implement the IAccount
interface and define custom logic for validating signatures, nonces, and executing transactions.
Key Functions:
validateUserOp
: Ensures the UserOperation is valid by verifying the signature and nonce.execute
: Executes the transaction specified in thecallData
.
Paymasters are special contracts that can sponsor gas fees for users. This enables gasless transactions, where the user does not need to hold ETH to pay for gas.
Key Functions:
validatePaymasterUserOp
: Checks if the paymaster is willing to pay for the operation's gas.postOp
: Handles post-operation logic like reimbursements after the UserOperation is processed.
Use Cases:
- Gasless Transactions: Users can perform actions without holding native tokens by having the Paymaster cover the gas fees.
- Sponsored Transactions: DApps can sponsor user interactions to improve onboarding.
Bundlers are off-chain actors that aggregate multiple UserOperation
s into a single transaction to be processed by the EntryPoint
. They are similar to miners or block producers but specifically for UserOperations.
Responsibilities:
- Collect
UserOperation
s from the mempool. - Package and submit them to the
EntryPoint
viahandleOps
. - Receive a fee for the gas costs paid on behalf of users.
An optional component that can be used to aggregate signatures from multiple users, optimizing the size of UserOperation
s when handling multiple transactions.
Use Case:
- Signature Aggregation: Reduces the size of the batch by combining signatures, lowering the overall gas cost.
-
User Signs a Transaction:
- The user (or DApp) creates a
UserOperation
object with all necessary fields and signs it using their EOA or a session key.
- The user (or DApp) creates a
-
Broadcast to Mempool:
- The signed
UserOperation
is sent to a public mempool where bundlers can pick it up.
- The signed
-
Bundler Aggregates UserOperations:
- The bundler selects multiple UserOperations and sends them to the
EntryPoint
contract usinghandleOps
.
- The bundler selects multiple UserOperations and sends them to the
-
EntryPoint Validates and Executes:
- The
EntryPoint
verifies the signatures and nonces. If valid, it forwards the call to the Smart Account'sexecute
function.
- The
-
Paymaster (Optional):
- If a paymaster is specified, it covers the gas costs on behalf of the user.
-
Smart Account Executes the Call:
- The Smart Account executes the desired function call (
callData
).
- The Smart Account executes the desired function call (
- Customizable Account Logic: Users can create accounts with advanced features like multi-sig, social recovery, and session keys.
- Gasless Transactions: Paymasters allow users to interact with the blockchain without needing ETH for gas fees.
- Enhanced Security: Smart Accounts can have built-in security features such as rate limiting and account recovery.
- Improved User Experience: Enables features like one-click onboarding and gasless transactions for a seamless DApp experience.
{
"sender": "0xYourSmartAccountAddress",
"nonce": 1,
"initCode": "0x",
"callData": "0x",
"callGasLimit": 100000,
"verificationGasLimit": 100000,
"preVerificationGas": 21000,
"maxFeePerGas": "20000000000",
"maxPriorityFeePerGas": "1000000000",
"paymasterAndData": "0xPaymasterAddress",
"signature": "0xUserSignature"
}
Account Abstraction via ERC-4337 brings a new level of flexibility and customization to Ethereum accounts, enabling a wide range of innovative use cases. By separating account management logic from traditional EOAs and introducing programmable Smart Accounts, ERC-4337 enhances the capabilities of Ethereum wallets and improves the overall user experience.