Account abstraction lab: smart accounts, ERC-4337, paymasters and EIP-7702 on a local chain
This lab gives each student a local test chain of their own, anvil from Foundry, with a smart account, an EntryPoint, a paymaster, a counter to call and two EIP-7702 delegates already deployed. Eight short scripts each show one idea: an ordinary account beside a smart account, a UserOperation carried by a bundler, what validation refuses, a paymaster paying for an empty account, a session key with a spending limit, a delegation set and undone, a signed delegation that empties an account, and the same payment made three ways. Every script returns the chain to how it started, so it prints the same every time.
Nothing here is money. The chain runs only inside the student's copy, the keys are the public test keys every Foundry guide prints, and every copy has no route to the internet, to any public chain or to any other student. There are no coin prices or trading anywhere in it.
What students learn
Why one private key is fragile: a lost key locks an ordinary account, a leaked one empties it, and it must pay its own gas. How ERC-4337 works: a user signs a UserOperation, a bundler sends it to the EntryPoint, which validates every operation and then executes them; in the lab one operation takes a counter from 0 to 1 for gas 114672, and a bad signature and a replayed nonce are refused with AA24 and AA25. How a paymaster pays for an account with no ETH and refuses strangers and costly operations, how a session key pays a shop twice and is refused at its limit, and how an EIP-7702 delegation gives an ordinary account code, shown as 0xef0100 and an address. It suits blockchain, security and software engineering courses; check your own awarding body's unit for the exact wording, none is quoted here.
Run it in your browser
The lab starts one service, chain, which writes the contracts, their compiled code, aa.sh and the scripts into its home folder, starts anvil and deploys, with nothing downloaded. There is no web page: the terminal is the lab. It has no cast of its own, so it reaches the lab with docker exec chain, followed by the command to run inside.
- Open the Container page. Open Build on the bar and choose Run a container. Anybody may open it, and the Git lab and the SQL lab start with no account. Every other lab needs a free account: create one, sign in, then press Start.
- Find the lab. The Sample labs card lists every sample. Find Smart accounts: ERC-4337, paymasters and EIP-7702.
- Press Start. Start runs it as it is, in one press. Edit the file first opens the compose file so you can change it before you start.
- Open it. On the lab's page, press Open terminal and type docker exec chain ./steps/userop.sh to see one UserOperation signed, sent by the bundler and run by the EntryPoint. The contracts are in src, so docker exec chain cat src/SmartAccount.sol shows the smart account to read.
What to ask students to hand in
A few lines on one script they changed and ran, such as a session key with a different limit or a paymaster with a lower cap, with what it printed and a sentence or two in their own words on what they learned. Nothing is marked automatically: the sentence shows whether it was understood. For stronger work ask them to say what a wallet should have shown before the signature in the phishing script.
A basic lesson on this lab
Smart Account Basics is a small lesson worked in this lab. In it a student compares an ordinary account with a smart account, sends one UserOperation through the bundler, has a paymaster pay for an empty account, spends with a session key until its limit, and delegates an ordinary account with EIP-7702.
Free personal accounts have it in the Basics module, which is on Home, and every college can copy it from the Library's Basics folder. It is deliberately small: it shows a teacher what a lesson worked in a lab is, and the lab does the rest. Copy it into a module of your own to change it. The undergraduate module Smart accounts: account abstraction on a local chain is worked in the same lab.
The code on GitHub
The compose file has no Dockerfile: it runs one stock public image, Foundry's own, pinned to a release tag, as its own unprivileged account with 256 MB of memory. The image is licensed MIT or Apache-2.0 and is not distributed by us. The file writes every contract and script from fixed text when it starts. The lab has no compiler and downloads nothing, so the contracts arrive compiled by us, beside their source. The limits are honest ones: the EntryPoint is a simplified teaching model with the real one's shape and none of its safeguards, and the bundler is a shell function that simulates a bundle and then sends it. EIP-7702 is real, on anvil's Prague rules. Nothing is kept when the lab stops.
Set it as work
Say in the task what to hand in.
- Make the lab. In your module add a task and choose the Container lab card, then In a GitHub repository. Give https://github.com/mitsurutech/lab-aa-lab with the branch main. The compose file is the default, compose.yaml. Fork the repository first if you want to change it, for example to give the paymaster a different cap or the session key a different limit.
- Publish and try it. Publish pins the commit you were shown, so a later change in the repository does not alter a lab you have already set. Start your own copy first.
- Hand it out. Assign it like any task, with a due date if you want one, and say in the task what to do and what to hand in.
- Mark what is handed in. Open a student’s copy and the work they handed in, mark it, and send it back with a reason if it needs more.
Try this lab, and what it costs
A free personal account can work through the basic lessons in this lab, with enough free credit each month to follow most lessons and no card. For a class, a school or college has its first 365 days free for up to 50 students, then pays per student a year, with every lab included and staff free.
Questions people ask
- Is any of this real money?
- No. The chain is anvil, a local test chain inside the student's own copy, and the keys are the well-known test keys. The lab cannot reach the internet or any public chain. Never use those keys anywhere else.
- Why does the terminal use docker exec chain?
- The lab's terminal carries a few clients and no cast. docker exec chain runs a command inside the lab's own container, which has anvil and cast.
- Is this the real EntryPoint and a real bundler?
- No. The real EntryPoint, version 0.7 or 0.8, and a real bundler need tooling the lab does not carry. The lab's EntryPoint keeps the same shape, validation then execution then paying the bundler, and the same error codes, and the bundler is a shell function in aa.sh. Use the audited EntryPoint for anything real.
- Why does every script print the same each time?
- Each script first returns the chain to the snapshot saved when the contracts were deployed, and every key and gas price is fixed. So the scripts can run in any order and still print what the lessons say.