How do ERC-4337 smart contract wallets work?
Smart contract wallets that use Account Abstraction (ERC-4337) create a wallet that is managed using a smart contract instead of a wallet that is managed by a single private key like EOA wallets (Externally Owned Address).
The programmable nature of smart contract wallets allows for the development of a wide range of new use cases. By reducing complexity without compromising security or anonymity, smart contract wallets will help facilitate onboarding of the next wave of blockchain users.
What are smart contract wallets?
Smart contract wallets store and manage digital assets (e.g. cryptocurrency, NFTs, etc.) using smart contracts. Smart contract wallets are the foundation of account abstraction: the process of unifying the various Ethereum account types into a single type by ‘abstracting’ an account’s control away from the network and defining it with a smart contract.
Some examples of smart contract wallets that use ERC-4337:
Two main smart contract wallets that don't use ERC-4337 are Safe and Argent.
What are contract accounts (CAs)?
Also known as smart contracts, contract accounts contain code which manages the exchange of information between parties. Contract accounts are used in every DeFi protocol, NFT collection, or ERC-20 token.
All of the contract's business logic and state variables are stored on-chain. Because the state and code of a smart contract is stored on-chain, the externally-owned account deploying it must pay a fee.
Note: In web3 programming, there is a ‘smart contract factory’ pattern, where a contract can deploy other contracts via a predefined interface. Even in this case, the transaction initiating it must originate with and be paid for by an EOA.
How do Contract Accounts work differently compared to Externally Owned Accounts (EOAs)?
The main difference between smart contract accounts and EOA accounts is that smart contract accounts can contain logic. Because only EOA accounts can initiate transactions smart contract accounts rely on Bundlers' EOA account to bundle user operations into a single transaction that is posted on the blockchain.
Under current Ethereum protocol, EOAs are the only account type that can initiate a transaction, whether it’s a contract call or a value transfer. Even in the case of a contract account calling another contract account, the origin of the transaction always comes from an externally-owned account.
Here's a comparison of contract accounts and EOA accounts:
So how do smart contract wallets execute transactions if they can't initiate transactions on their own?
How ERC-4337 Smart Contract Wallets Work
Because Smart Contract wallets can not initiate a transaction, they must be called by an EOA wallet. This process is supported by multiple Account Abstraction infrastructure providers (e.g. Bundlers) and smart contracts (e.g. EntryPoint)
The typical flow of a smart contract wallet transaction is:
A user wants to execute a UserOperation
UserOperations are sent to an "alternative mempool"
A Bundler with an EOA wallet bundles and sends all of the UserOperations to the EntryPoint contract
The EntryPoint contract validates and executes all of the UserOperations
The EOA wallet that bundled the UserOperations is repaid the ETH they spent on behalf of the users by the users' wallets or the Paymaster
While understanding how smart contract wallets work from a technical perspective may be difficult to understand, for end users, smart contract wallets provide many improvements compared to EOA wallets such as programmability and the ability for features like social recovery.
Additonal Resources for Learning How Smart Contract Wallets Work
For more information on how each component of Account Abstraction works read our series, "You Could Have Invented Account Abstraction," which was written by David Philipson, on Alchemy's Account Abstraction Infrastructure engineering team.
Learn The Reasons Why Developers Are Adopting Account Abstraction Over Meta Transactions
Explore Meta Transactions, Covering Gas Fees and Understanding Why They’re No Longer the Ideal Solution.
Discover How Smart Contract Accounts Use Modules and Plugins to Create New Extensions