⚡ Tóm tắt — Đọc trong 60 giây
ERC-4337: Smart contract thay thế EOA mà không cần hard fork
ERC-4337 (Account Abstraction) là chuẩn Ethereum cho phép dùng smart contract làm "ví" thay vì EOA (Externally Owned Account), mà không cần thay đổi Ethereum protocol. Điều này unlock: trả gas bằng ERC-20 (không cần ETH), batch nhiều giao dịch trong 1 call, social recovery khi mất key, passkey/Face ID signing, và session keys cho game/dApp.
Kiến trúc cốt lõi: UserOperation (giao dịch dạng mới) → Bundler (node gom UserOps) → EntryPoint (smart contract trung tâm) → Account Contract (ví của user). Optional: Paymaster (trả gas thay user) và Factory (deploy account contract mới).
UserOperation
Giao dịch mới
Thay thế transaction — chứa logic phức tạp hơn
EntryPoint
Cổng vào duy nhất
Smart contract validate và execute mọi UserOp
Bundler
Node đặc biệt
Gom UserOps, submit lên chain, kiếm gas fee
Paymaster
Gas sponsor
Trả gas thay user — gasless transactions
Ethereum account hiện tại có hai loại: EOA (Externally Owned Account — kiểm soát bởi private key) và Contract Account (kiểm soát bởi code). MetaMask, Trust Wallet, Ledger — tất cả đều là EOA. EOA đơn giản và hiệu quả, nhưng có những giới hạn cơ bản không thể vượt qua:
| Giới hạn EOA | Vấn đề thực tế | Tác động |
| Phải có ETH để trả gas | User mới cần ETH trước khi dùng được bất kỳ dApp nào — chicken-and-egg problem | UX rất tệ |
| Không có recovery | Mất private key = mất tất cả vĩnh viễn — không có bất kỳ cơ chế nào | Risk cực cao |
| Không batch transactions | Approve + Swap cần 2 transaction riêng biệt — 2 lần confirm, 2 lần gas | Friction cao |
| Signature cứng: ECDSA | Không thể dùng Face ID, Touch ID, WebAuthn — phải dùng secp256k1 key | Khó onboard |
| Không có logic điều kiện | Không thể: spending limit, time lock, multi-sig xác nhận trên 1 key | Thiếu flexibility |
| Không có session key | Game/dApp cần ký từng action — 100 moves trong game = 100 lần confirm MetaMask | Không thể dùng |
Giải pháp lý tưởng là dùng smart contract làm account — code có thể implement recovery, multi-sig, session key, custom signature scheme. Nhưng vấn đề: ai submit transaction để trigger smart contract account? Transaction Ethereum phải đến từ EOA. Đây chính là circular dependency mà ERC-4337 giải quyết.
Để hiểu sự khác biệt sâu hơn giữa EOA và smart contract wallet, xem: EOA vs Smart Contract Wallet — So sánh toàn diện
ERC-4337 được đề xuất bởi Vitalik Buterin và các đồng tác giả tháng 9/2021, deploy mainnet tháng 3/2023. Ý tưởng cốt lõi: tạo một "alt mempool" riêng biệt cho UserOperations, với một smart contract đặc biệt (EntryPoint) làm người trung gian — không cần thay đổi gì ở Ethereum consensus layer hay protocol.
Insight then chốt: Tách biệt "ý định" và "execution"
Với EOA: bạn tạo và ký transaction → submit thẳng lên mempool → miner/validator execute. Với ERC-4337: bạn tạo UserOperation (ý định) → Bundler submit lên EntryPoint → EntryPoint verify và execute qua Account Contract. Bạn không cần có ETH, không cần submit transaction trực tiếp.
💡
Tên gọi phổ biến
ERC-4337, Account Abstraction (AA), Smart Wallet, Smart Account — đều chỉ cùng tiêu chuẩn. "Account Abstraction" là tên conceptual, "ERC-4337" là tên EIP specification. Bạn sẽ thấy cả hai trong documentation và sản phẩm.
// ERC-4337 System Architecture
User tạo & ký
UserOperation (không phải tx thông thường)
↓ submit đến Alt Mempool (P2P network riêng)
Bundler Node validate, gom nhiều UserOps, tạo 1 transaction
↓ call EntryPoint.handleOps([UserOp1, UserOp2, ...])
EntryPoint Contract (0x0000000071727De22E5E9d8BAf0edAc6f37da032)
├─ [Optional] Paymaster.validatePaymasterUserOp() → xác nhận ai trả gas
├─ [Optional] Factory.createAccount() → deploy account nếu chưa có
└─ Account.validateUserOp() → verify signature
↓ nếu validation pass
Account Contract execute calldata (swap, transfer, batch...)
↓ kết quả
On-chain state change + refund gas to Bundler
1. UserOperation — "Transaction" mới của ERC-4337
UserOperation không phải Ethereum transaction thông thường — đó là một struct với nhiều fields hơn, bao gồm cả logic validation và payment:
// UserOperation struct (ERC-4337 v0.7)
struct PackedUserOperation {
address sender; // Smart wallet address (Account Contract)
uint256 nonce; // Replay protection
bytes initCode; // Factory + calldata nếu wallet chưa deploy
bytes callData; // Action thực sự: swap, transfer, batch...
bytes32 accountGasLimits; // verificationGasLimit | callGasLimit (packed)
uint256 preVerificationGas;// Gas overhead trước validation
bytes32 gasFees; // maxPriorityFeePerGas | maxFeePerGas (packed)
bytes paymasterAndData; // Paymaster address + data (optional)
bytes signature; // Chữ ký của user — bất kỳ scheme nào!
}
// Signature field linh hoạt: ECDSA, multisig, WebAuthn P-256, BLS, zkProof...
2. EntryPoint — Smart contract trung tâm
EntryPoint là contract duy nhất và cố định trên mỗi chain, do Ethereum Foundation deploy và verify. Địa chỉ cố định: 0x0000000071727De22E5E9d8BAf0edAc6f37da032 (v0.7 trên mọi EVM chain). EntryPoint làm hai việc chính: validate UserOp (gọi Account Contract để verify signature) và execute UserOp (gọi Account Contract để thực hiện action).
3. Account Contract — Smart wallet của user
Đây là smart contract đóng vai trò "ví" của user — thay thế EOA. Account Contract cần implement hai function tối thiểu: validateUserOp() (verify chữ ký) và execute() (thực hiện action). Ngoài ra có thể có: batch execute, social recovery logic, spending limit, session key management, và bất kỳ custom logic nào.
4. Factory — Counterfactual deployment
ERC-4337 hỗ trợ counterfactual deployment: bạn có thể biết địa chỉ smart wallet của mình TRƯỚC KHI deploy, nhờ CREATE2. Factory contract được dùng để deploy Account Contract lần đầu tiên — được trigger tự động trong UserOperation đầu tiên. User có thể nhận token vào địa chỉ ví chưa deploy — chỉ deploy khi dùng lần đầu.
Hiểu flow đầy đủ giúp developer debug và user biết tại sao transaction ERC-4337 đôi khi fail ở bước khác so với EOA transaction.
| Bước | Actor | Hành động | On-chain? |
| 1 | User / Wallet app | Tạo UserOperation struct, điền callData, ký bằng private key (hoặc passkey) | Không |
| 2 | Wallet app | Submit UserOperation đến Bundler node qua RPC | Không |
| 3 | Bundler | Simulate UserOp off-chain: gọi simulateValidation() để check nếu sẽ pass | Không |
| 4 | Bundler | Gom nhiều valid UserOps thành 1 bundle | Không |
| 5 | Bundler | Submit bundle lên chain: EntryPoint.handleOps(bundle) | Có |
| 6 | EntryPoint | Validation loop: gọi Account.validateUserOp() cho từng UserOp, verify paymaster | Có |
| 7 | EntryPoint | Execution loop: gọi Account.execute(callData) cho từng UserOp đã pass validation | Có |
| 8 | EntryPoint | Refund gas cho Bundler, gọi Paymaster.postOp() nếu có | Có |
📌
Separation: Validation vs Execution
ERC-4337 tách biệt hai phase: validation (ai được phép?) và execution (làm gì?). Validation chạy trước và phải revert-safe — không được có storage writes tùy ý. Execution chạy sau và có toàn quyền. Tách biệt này ngăn re-entrancy attacks và cho phép Bundler simulate off-chain trước khi commit.
Bundler là infrastructure node mới trong ERC-4337 ecosystem. Bất kỳ ai cũng có thể run Bundler — đây là thị trường cạnh tranh với nhiều nhà cung cấp công khai.
Bundler kiếm tiền thế nào?
Bundler submit một Ethereum transaction (dùng EOA của mình) gọi EntryPoint.handleOps(). Chi phí gas của transaction này được Bundler trả trước. Sau khi execution hoàn thành, EntryPoint refund gas cho Bundler từ deposit của Account Contract (hoặc Paymaster). Lợi nhuận của Bundler = gas user đã trả - gas thực tế tiêu thụ + tip.
// Bundler profit calculation (simplified)
gas_paid_by_user = preVerificationGas + verificationGasLimit + callGasLimit
gas_actual_used = gas thực tế tiêu thụ trong handleOps()
bundler_profit = (gas_paid_by_user - gas_actual_used) * gasPrice + tip
// Risk: simulation vs execution divergence
// Nếu gas thực tế > gas_paid_by_user → Bundler lỗ → Bundler reject UserOp
// ERC-4337 có các anti-DoS rules để ngăn UserOps tốn gas hơn declare
Bundler providers hiện tại (2025)
| Provider | Type | Chains | Đặc điểm |
| Pimlico | Commercial | 50+ chains | Bundler + Paymaster service, permissive policy |
| Alchemy Rundler | Commercial | 20+ chains | Tích hợp với Alchemy Account Kit |
| Stackup | Commercial | 15+ chains | Bundler API thuần túy, enterprise focus |
| Biconomy Bundler | Commercial | 30+ chains | Tích hợp với Biconomy SDK |
| Self-hosted | Open source | Any EVM | eth-infinitism reference, Silius (Rust) |
Để đọc thêm về Bundler và UserOperation chi tiết, xem: Bundler Là Gì? UserOperation Giải Thích Từ A đến Z
Paymaster là smart contract cho phép bên thứ ba trả gas thay user — hoặc cho phép user trả gas bằng ERC-20 token thay vì native ETH. Đây là một trong những tính năng UX quan trọng nhất của ERC-4337.
Hai loại Paymaster phổ biến
| Loại | Cơ chế | Use case |
| Sponsoring Paymaster | dApp / protocol trả gas hoàn toàn — user không cần ETH | Onboarding mới, airdrop, game, loyalty program |
| ERC-20 Paymaster | User trả gas bằng USDC/USDT/token khác — Paymaster convert sang ETH | User có token nhưng không có ETH |
| Subscription Paymaster | User nạp ETH vào Paymaster trước, tự động trả gas | Recurring payments, automation |
| NFT-gated Paymaster | Chỉ holder NFT cụ thể được sponsored gas | NFT membership benefit |
// Sponsoring Paymaster — interface tối thiểu (Solidity)
interface IPaymaster {
// EntryPoint gọi trước execution — quyết định có sponsor không
function validatePaymasterUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash,
uint256 maxCost
) external returns (bytes memory context, uint256 validationData);
// EntryPoint gọi sau execution — cleanup, refund, logging
function postOp(
PostOpMode mode,
bytes calldata context,
uint256 actualGasCost,
uint256 actualUserOpFeePerGas
) external;
}
// Ví dụ: Sponsor chỉ dApp cụ thể
function validatePaymasterUserOp(...) external returns (...) {
// Decode callData để kiểm tra user đang gọi dApp nào
address target = abi.decode(userOp.callData[4:], (address));
require(target == MY_DAPP_ADDRESS, "Only sponsor our dApp");
return ("", 0); // OK — sponsor this
}
Để hiểu sâu hơn về Paymaster design patterns, xem: Paymaster Là Gì? Gas Sponsorship và ERC-20 Gas Payment
EIP-7702 (Pectra hardfork, dự kiến 2025) là một cách tiếp cận khác để đạt Account Abstraction. Hai cách này không loại trừ nhau — chúng phục vụ use case khác nhau:
| Tiêu chí | ERC-4337 | EIP-7702 |
| Cách tiếp cận | Smart contract account mới | EOA tạm thời set code |
| Hard fork cần? | Không — pure smart contract | Có — Ethereum protocol change |
| User cần gì? | Tạo smart wallet mới | Dùng EOA hiện có |
| Persistence | Permanent smart wallet | Code chỉ set cho 1 transaction |
| Phù hợp với | Full-featured smart wallet, custody | Upgrade EOA tạm thời, quick batch |
| Adoption barrier | Cần migrate sang smart wallet | Không cần migrate — dùng MetaMask EOA |
| Gas overhead | 20K–42K gas deployment + 15K–25K per op | Thấp hơn — không deploy contract riêng |
| Timeline | Live từ 3/2023 | Pectra 2025 |
✅
Kết luận: Cả hai cùng tồn tại
ERC-4337 tốt cho full-featured smart wallet với recovery, module system, custom logic. EIP-7702 tốt cho "nâng cấp nhanh" EOA hiện có để batch, sponsor gas mà không cần tạo ví mới. Long term: hầu hết power user sẽ dùng ERC-4337 smart wallet; mainstream user được benefit từ EIP-7702 via existing wallet apps.
Smart wallet implementations phổ biến
| Project | Type | Đặc điểm nổi bật |
| Safe (Gnosis Safe) | Multisig + ERC-4337 | Phổ biến nhất cho DAO/treasury, $100B+ assets secured |
| Biconomy Smart Account | Modular AA | ERC-7579 modules, Paymaster service |
| ZeroDev Kernel | Modular AA | Plugin system, passkey support |
| Alchemy Light Account | Lightweight AA | Gas-optimized, simple use cases |
| Coinbase Smart Wallet | Consumer AA | Passkey native, gasless onboarding |
Developer SDK để build với ERC-4337
// Ví dụ: Gửi gasless UserOperation với Alchemy Account Kit (TypeScript)
import { createModularAccountAlchemyClient } from "@alchemy/aa-alchemy";
import { LocalAccountSigner, sepolia } from "@alchemy/aa-core";
const client = await createModularAccountAlchemyClient({
apiKey: "YOUR_ALCHEMY_KEY",
chain: sepolia,
signer: LocalAccountSigner.privateKeyToAccountSigner(PRIVATE_KEY),
gasManagerConfig: {
policyId: "YOUR_GAS_POLICY_ID" // Paymaster policy — sponsor gas
}
});
// Gửi UserOperation — user không cần ETH!
const result = await client.sendUserOperation({
uo: {
target: "0xRecipientAddress",
data: "0x",
value: BigInt(0)
}
});
const txHash = await client.waitForUserOperationTransaction(result);
console.log("Done:", txHash);
ERC-4337 adoption metrics (2025)
Tính đến đầu 2025, hàng triệu UserOperations đã được xử lý trên Ethereum mainnet và L2 chains. Base (Coinbase L2) là chain có nhiều UserOps nhất do Coinbase Smart Wallet tích hợp ERC-4337 native. Polygon và Arbitrum cũng có adoption cao nhờ gas thấp. Entry barrier đang giảm mạnh: Coinbase, Shopify và nhiều consumer apps đã tích hợp gasless UX cho user bằng Paymaster sponsorship.
ERC-4337 có thay thế MetaMask không?+
Không — MetaMask là UI/UX layer, ERC-4337 là account model. Hai layers hoàn toàn khác nhau trong stack. MetaMask đã và đang tích hợp ERC-4337 smart wallets qua Snaps và native features. ERC-4337 thay đổi loại account bạn dùng (EOA vs smart contract account), không thay đổi cách bạn interact với wallet UI. User cuối sẽ chỉ thấy UX tốt hơn: gasless, batch, recovery.
ERC-4337 và EIP-7702 khác nhau thế nào?+
ERC-4337 tạo smart contract account mới hoàn toàn — bạn dùng một smart wallet contract thay vì EOA, không cần hard fork. EIP-7702 (Pectra 2025) cho phép EOA hiện có tạm thời set code trong một transaction, unlock batch transactions và sponsored gas mà không cần migrate. Không loại trừ nhau: ERC-4337 tốt cho full-featured smart wallet; EIP-7702 tốt để upgrade EOA hiện có không cần tạo ví mới.
Bundler kiếm tiền thế nào?+
Bundler submit Ethereum transaction (dùng EOA của mình) gọi EntryPoint.handleOps() và trả gas trước. Sau execution, EntryPoint refund gas từ Account/Paymaster deposit. Bundler profit = gas user khai báo sẵn sàng trả − gas thực tế tiêu thụ + tip (priority fee). Đây là thị trường cạnh tranh — Pimlico, Stackup, Alchemy cung cấp Bundler API public với pricing cạnh tranh.
Smart wallet ERC-4337 có tốn gas hơn EOA không?+
Có — overhead ~20K–42K gas deployment (một lần duy nhất, counterfactual) và ~15K–25K gas mỗi UserOperation so với EOA transaction tương đương. Tuy nhiên overhead này thường được offset bằng: batch transactions (nhiều actions một UserOp), Paymaster sponsored gas (user không trả), và ERC-20 gas payment. Net: user trải nghiệm thường tốt hơn dù protocol overhead cao hơn.
ERC-4337 đã deploy trên mainnet Ethereum chưa?+
Có — EntryPoint v0.6 deploy từ tháng 3/2023, v0.7 từ tháng 2/2024 trên Ethereum mainnet. Cũng available trên Polygon, Arbitrum, Optimism, Base, Avalanche và hầu hết EVM chains. Tính đến 2025, hàng triệu UserOperations đã processed, chủ yếu từ Coinbase Smart Wallet, Safe, Biconomy, ZeroDev. Base là chain có adoption cao nhất nhờ tích hợp native với Coinbase.
Tài liệu tham khảo
Tài liệu kỹ thuật được kiểm chứng — EIPs chính thức và protocol documentation.
- Buterin, V. et al. ERC-4337: Account Abstraction Using Alt Mempool. eips.ethereum.org/EIPS/eip-4337. 2021. — Specification gốc ERC-4337.
- Ethereum EIPs. EIP-7702: Set EOA account code for one transaction. eips.ethereum.org/EIPS/eip-7702. 2024. — EIP-7702 Pectra.
- Ethereum EIPs. ERC-7579: Minimal Modular Smart Accounts. eips.ethereum.org/EIPS/eip-7579. 2023. — Module standard cho smart wallet.
- eth-infinitism. Account Abstraction Reference Implementation. github.com/eth-infinitism/account-abstraction. 2023. — Reference implementation EntryPoint + Account.
- Gnosis Safe. Safe{Core} Protocol — ERC-4337 Integration. docs.safe.global. 2024.
- Pimlico. ERC-4337 Bundler & Paymaster API Documentation. docs.pimlico.io. 2024.
- ZRO Research. Wallet Infrastructure & Key Management — TWT.VN. twt.vn/. 2025–2026.