Bỏ qua navigation
⚡ 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

Vấn Đề Của EOA — Tại sao cần Account Abstraction

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 EOAVấn đề thực tếTác động
Phải có ETH để trả gasUser mới cần ETH trước khi dùng được bất kỳ dApp nào — chicken-and-egg problemUX rất tệ
Không có recoveryMất private key = mất tất cả vĩnh viễn — không có bất kỳ cơ chế nàoRisk cực cao
Không batch transactionsApprove + Swap cần 2 transaction riêng biệt — 2 lần confirm, 2 lần gasFriction cao
Signature cứng: ECDSAKhông thể dùng Face ID, Touch ID, WebAuthn — phải dùng secp256k1 keyKhó onboard
Không có logic điều kiệnKhông thể: spending limit, time lock, multi-sig xác nhận trên 1 keyThiếu flexibility
Không có session keyGame/dApp cần ký từng action — 100 moves trong game = 100 lần confirm MetaMaskKhô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 Là Gì — Giải pháp không cần hard fork

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.

Kiến Trúc Hệ Thống — 5 thành phần cốt lõi

// 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.

UserOperation Flow — Từ user click đến on-chain execution

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ướcActorHành độngOn-chain?
1User / Wallet appTạo UserOperation struct, điền callData, ký bằng private key (hoặc passkey)Không
2Wallet appSubmit UserOperation đến Bundler node qua RPCKhông
3BundlerSimulate UserOp off-chain: gọi simulateValidation() để check nếu sẽ passKhông
4BundlerGom nhiều valid UserOps thành 1 bundleKhông
5BundlerSubmit bundle lên chain: EntryPoint.handleOps(bundle)
6EntryPointValidation loop: gọi Account.validateUserOp() cho từng UserOp, verify paymaster
7EntryPointExecution loop: gọi Account.execute(callData) cho từng UserOp đã pass validation
8EntryPointRefund gas cho Bundler, gọi Paymaster.postOp() nếu 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 Economics — Ai vận hành và kiếm gì

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)

ProviderTypeChainsĐặc điểm
PimlicoCommercial50+ chainsBundler + Paymaster service, permissive policy
Alchemy RundlerCommercial20+ chainsTích hợp với Alchemy Account Kit
StackupCommercial15+ chainsBundler API thuần túy, enterprise focus
Biconomy BundlerCommercial30+ chainsTích hợp với Biconomy SDK
Self-hostedOpen sourceAny EVMeth-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 Design — Gas sponsorship và ERC-20 gas payment

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ạiCơ chếUse case
Sponsoring PaymasterdApp / protocol trả gas hoàn toàn — user không cần ETHOnboarding mới, airdrop, game, loyalty program
ERC-20 PaymasterUser trả gas bằng USDC/USDT/token khác — Paymaster convert sang ETHUser có token nhưng không có ETH
Subscription PaymasterUser nạp ETH vào Paymaster trước, tự động trả gasRecurring payments, automation
NFT-gated PaymasterChỉ holder NFT cụ thể được sponsored gasNFT 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

ERC-4337 vs EIP-7702 — Hai con đường đến Account Abstraction

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-4337EIP-7702
Cách tiếp cậnSmart contract account mớiEOA tạm thời set code
Hard fork cần?Không — pure smart contractCó — Ethereum protocol change
User cần gì?Tạo smart wallet mớiDùng EOA hiện có
PersistencePermanent smart walletCode chỉ set cho 1 transaction
Phù hợp vớiFull-featured smart wallet, custodyUpgrade EOA tạm thời, quick batch
Adoption barrierCần migrate sang smart walletKhông cần migrate — dùng MetaMask EOA
Gas overhead20K–42K gas deployment + 15K–25K per opThấp hơn — không deploy contract riêng
TimelineLive từ 3/2023Pectra 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.

Triển Khai Thực Tế — Ecosystem, SDK và case studies 2025

Smart wallet implementations phổ biến

ProjectTypeĐặc điểm nổi bật
Safe (Gnosis Safe)Multisig + ERC-4337Phổ biến nhất cho DAO/treasury, $100B+ assets secured
Biconomy Smart AccountModular AAERC-7579 modules, Paymaster service
ZeroDev KernelModular AAPlugin system, passkey support
Alchemy Light AccountLightweight AAGas-optimized, simple use cases
Coinbase Smart WalletConsumer AAPasskey 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.

🔗
Liên kết trong ERC-4337 cluster
Để hiểu đầy đủ hệ sinh thái AA: Paymaster Là Gì? — gas sponsorship chi tiết; Bundler Là Gì? — UserOperation lifecycle đầy đủ; EOA vs Smart Contract Wallet — so sánh toàn diện.

FAQ — Câu hỏi thường gặp về ERC-4337

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 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 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.
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.
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.

  1. Buterin, V. et al. ERC-4337: Account Abstraction Using Alt Mempool. eips.ethereum.org/EIPS/eip-4337. 2021. — Specification gốc ERC-4337.
  2. Ethereum EIPs. EIP-7702: Set EOA account code for one transaction. eips.ethereum.org/EIPS/eip-7702. 2024. — EIP-7702 Pectra.
  3. Ethereum EIPs. ERC-7579: Minimal Modular Smart Accounts. eips.ethereum.org/EIPS/eip-7579. 2023. — Module standard cho smart wallet.
  4. eth-infinitism. Account Abstraction Reference Implementation. github.com/eth-infinitism/account-abstraction. 2023. — Reference implementation EntryPoint + Account.
  5. Gnosis Safe. Safe{Core} Protocol — ERC-4337 Integration. docs.safe.global. 2024.
  6. Pimlico. ERC-4337 Bundler & Paymaster API Documentation. docs.pimlico.io. 2024.
  7. ZRO Research. Wallet Infrastructure & Key Management — TWT.VN. twt.vn/. 2025–2026.
₿ TWT.VN · Knowledge Base

Khám Phá Thêm — Wallet Infrastructure

Mỗi bài đi sâu vào một chủ đề kỹ thuật — cùng nhau tạo thành bộ tài liệu Wallet Infrastructure đầy đủ nhất tiếng Việt.