이 레포지토리는 EIP-4337(Account Abstraction) 을 학습하기 위한 두 가지 스마트 계정 컨트랙트를 포함합니다.
MinimalSmartAccount.sol→ 최소 구현 (기본 뼈대)AdvancedSmartAccount.sol→ 실무 개념 반영 (ECDSA, Paymaster, 멀티시그)- 순서: UserOp → Alt-Mempool → EntryPoint.sol → MyAccount.sol → Paymaster.sol → 블록체인
- 직접 배포/실행 실습 → Node.js + Hardhat(or Foundry) + MetaMask + Sepolia ETH faucet → 전부 필요
- Node.js: Hardhat, Foundry 같은 개발 툴 실행 환경
- Hardhat (또는 Foundry): Solidity 컴파일/배포/테스트 프레임워크
- MetaMask: 테스트넷 계정 관리 (Sepolia 네트워크 추가)
- Sepolia ETH faucet: 테스트용 ETH 받기
<순서 정리> Node.js 설치 → Hardhat 프로젝트 초기화
라이브러리 설치 (Hardhat, OpenZeppelin, Account Abstraction)
컨트랙트 작성 → 컴파일 → 테스트
로컬 배포 or Sepolia 테스트넷 배포
MetaMask/Etherscan에서 컨트랙트 확인
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
npm install @openzeppelin/contracts
npm install @account-abstraction/contracts
npx hardhatnpm install @openzeppelin/contracts테스트넷 배포 (Sepolia)
npx hardhat run scripts/deploy.js --network sepolianpx hardhat compilenpx hardhat test# 터미널 1: 로컬 네트워크 실행
npx hardhat node
# 터미널 2: 로컬 네트워크에 배포
npx hardhat run scripts/deploy.js --network localhostnpx hardhat run scripts/deploy.js --network sepolianpx hardhat node # 터미널 1
npx hardhat run scripts/deploy.js --network localhost # 터미널 2require("@nomicfoundation/hardhat-toolbox");
module.exports = {
solidity: "0.8.20",
networks: {
sepolia: {
url: "https://sepolia.infura.io/v3/<YOUR_INFURA_KEY>",
accounts: ["0x<YOUR_PRIVATE_KEY>"],
},
},
};npx hardhat run scripts/deploy.js --network sepolia4337의 최소 개념을 담은 계정 컨트랙트
-
핵심 기능
- EntryPoint와 연결 (
IEntryPoint) validateUserOp()→ UserOperation 검증 (owner 존재 여부만 체크)execute()→ EntryPoint가 호출하는 트랜잭션 실행receive()→ ETH 입금 처리
- EntryPoint와 연결 (
-
학습 포인트
- Solidity 기본 문법 (constructor, state variables, modifier, require)
- 데이터 위치 (
calldata) - 접근 제어 (
onlyEntryPoint) - 저수준 호출 (
dest.call{value: value}(func))
실무에서 요구되는 주요 기능을 추가한 확장 버전
-
추가된 기능
- ECDSA 서명 검증 → OpenZeppelin 라이브러리 활용
- 멀티시그 오너쉽 → 여러 소유자,
requiredSignatures이상 서명 필요 - Paymaster 지원 → 가스비 대납 로직 (
missingFunds) execute()로 트랜잭션 실행receive()&fallback()으로 ETH 입금 및 예외 호출 처리
-
학습 포인트
- 인터페이스(
IEntryPoint)와 외부 라이브러리(import) - 배열/매핑 + 제어문(for/if)
- 에러 처리(require)
- 멀티시그 로직 (중복 방지, 유효 서명 카운트)
- Paymaster 구조 반영
- 인터페이스(
UserOperation is a struct that describes a transaction-like object sent on behalf of a user.
It is deliberately not called a "transaction" to avoid confusion.
Similar to a transaction, it contains:
tocalldatamaxFeePerGasmaxPriorityFeePerGasnoncesignature(defined by the account implementation, not the protocol)
-
Sender Smart contract account that initiates the
UserOperation. -
EntryPoint Singleton contract that executes bundled
UserOperations. Bundlers must whitelist the supportedEntryPoint. -
Bundler Node that collects and submits valid
UserOperationsviaentryPoint.handleOps(). -
Paymaster Contract that agrees to pay for gas on behalf of the sender.
-
Factory Helper contract for deploying new accounts if needed.
-
Aggregator Approver contract for shared verification of multiple
UserOperations. Defined in ERC-7766.
-
Canonical mempool Decentralized, permissionless P2P network exchanging valid
UserOperationsthat comply with ERC-7562. -
Alternative mempool P2P network that applies different validation rules.
Ether (or L2 native token) transferred by the account or Paymaster to the EntryPoint
to cover future gas costs.
- ERC-4337: Account Abstraction
- ERC-7562: Canonical mempool
- ERC-7766: Aggregators
- ERC-7796: Conditional Raw Tx RPC
두 컨트랙트에서 다루는 주요 문법:
pragma solidity ^0.8.20;→ 버전 지정contract, interface→ 컨트랙트 구조 정의constructor→ 생성자state variables→ 상태 변수 (storage)modifier→ 재사용 조건 로직require→ 조건 체크 + revertview, external, payable→ 함수 속성calldata, memory→ 데이터 위치receive(), fallback()→ ETH 입금 처리low-level call→dest.call{value: value}(func)
📖 참고