A Node.js application for experimenting with Ethereum Account Abstraction using Solady Smart Accounts and the Viem library with comprehensive testing on local Anvil blockchain.
This project demonstrates how to:
- Create and manage Smart Accounts (ERC-4337)
- Automatically fund smart accounts from EOA at startup if needed
- Execute user operations with optimized gas settings
- Handle self-funded transactions without requiring a paymaster
Just fund the EOA account that you load into the repo with test eths and you will be good to go to run the project.
SmartAccountManager: Main class that orchestrates smart account operationsFundingUtils: Handles automatic funding of smart accounts from EOAGasUtils: Provides gas estimation with bumping logic for reliable transactionsmain.js: Example usage showing a self-transaction
-
Install dependencies:
npm install
-
Create
.envfile from the sample:cp .env.sample .env
-
Configure your environment variables in
.env:PIMLICO_API_KEY=your_pimlico_api_key_here PRIVATE_KEY=0x...your_private_key_here
npm startThis runs the main example which:
- Creates a smart account
- Displays EOA and smart account balances
- Automatically funds the smart account if needed
- Executes a 0.001 ETH self-transaction
- Shows final balances
import { SmartAccountManager } from "./SmartAccountManager.js";
import { parseEther } from "viem";
const manager = new SmartAccountManager({
minBalance: parseEther("0.005"), // Custom minimum balance
rpcUrl: "https://your-custom-rpc.com", // Optional custom RPC
});
await manager.initialize();
await manager.displayBalances();
// Send to any address
await manager.transferTo("0x...", parseEther("0.001"));- Smart accounts are automatically funded from your EOA when balance falls below minimum threshold
- Configurable minimum balance (default: 0.01 ETH)
- Includes extra gas buffer for transactions
- Automatic gas estimation with bumping (+3 gwei max fee, +20% priority fee)
- Fallback gas values if estimation fails
- Extended timeouts for reliable transaction confirmation
- No paymaster required - smart account pays its own transaction fees
- Uses Pimlico bundler infrastructure for ERC-4337 operations
- Proper gas estimation for user operations
Currently configured for Ethereum Sepolia Testnet:
- RPC:
https://ethereum-sepolia-rpc.publicnode.com - Bundler:
https://api.pimlico.io/v2/sepolia/rpc - Chain: Sepolia (chain ID: 11155111)
PIMLICO_API_KEY: Your Pimlico API key for bundler servicesPRIVATE_KEY: Your EOA private key (will fund smart account operations)
This project uses Solady Smart Accounts with:
- Real contract deployments via Foundry on local Anvil testing
- Deterministic address generation using salt parameter
- ERC-4337 compliant implementation with EntryPoint integration
- Factory pattern for efficient smart account creation
Deployed Contract Addresses (Anvil):
- EntryPoint:
0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f - Solady Factory:
0x7a2088a1bFc9d81c55368AE168C2C02570cB814F - Implementation:
0x4A679253410272dd5232B3Ff7cF5dbB88f295319
For other supported smart account types, see: Viem Account Implementations
Comprehensive test suite with 56 tests using Vitest and local Anvil blockchain:
# Run all tests (requires anvil running)
npm test
# Run tests with detailed output
npm run test:claude
# Run tests in watch mode
npm run test:watch
# Deploy contracts manually (optional - done automatically)
npm run test:setupPrerequisites: Start Anvil in a separate terminal:
anvilReal Contract Deployment:
- Uses Foundry to deploy actual Solady ERC-4337 contracts
- EntryPoint, Factory, and Implementation contracts on local Anvil
- Automatic test account funding (10 ETH each)
- No mocking - full blockchain integration testing
Test Structure:
test/unit/- Unit tests forSmartAccountManager,FundingUtils,GasUtilstest/integration/- Complete integration tests with real smart accountstest/foundry/- Solady contract deployment via Forgetest/setup/- Global test configuration and bootstrapping
Coverage Areas:
- ✅ Smart account initialization with deterministic addresses
- ✅ Automatic EOA → Smart Account funding logic
- ✅ Gas optimization with bumping strategies
- ✅ User operation preparation and execution
- ✅ Balance management and monitoring
- ✅ Error handling and network failures
- ✅ Multi-account scenarios and transfers
Multi-Account Testing: The test suite creates multiple smart account managers to thoroughly test:
- Different Owners: Using separate EOA private keys (
testPrivateKeys[0],testPrivateKeys[1]) - Different Salt Values: Same owner with different salts (
"0x0","0x1") creates different smart account addresses - Deterministic Behavior: Same owner + same salt always generates the same smart account address
- Inter-Account Operations: Testing transfers between different smart accounts
- Independent Management: Each smart account maintains separate balances and operates independently
This mirrors real-world usage where users might create multiple smart accounts from a single EOA for different purposes (personal, business, savings, etc.).
Test Features:
- Real Solady contracts deployed fresh for each test run
- Parallel test execution with proper isolation
- Expected failure handling for incomplete bundler infrastructure
- Gas estimation testing with fallback scenarios
Say hi to @makevoid on X (Twitter)