The Future of Web3 Onboarding:
Account Abstraction

In this workshop, we will create a new web3 onboarding experience that allows users to interact with smart contracts without ever creating their own wallet, signing a transaction, or paying gas fees. We will leverage EIP-4337 account abstraction mechanisms to do so. But before we get our hands dirty, let's have a look at what is this about.

This workshop is heavily inspired in @jarrodWatts tutorial so I suggest you take a look at what this amazing guy did!

My name is Giancarlo, I'm the founder of Webstudio.so and I love web3 no-code tools.

ERC-4337 Overview

What is Account Abstraction?

ERC-4337 sets a new standard for infrastructure that can enable :

  • 1. Social recovery of wallet (i.e. losing your private keys won’t necessarily mean permanently losing access to your account).
  • 2. Perform atomic multi-operations (e.g. approve and swap in the same transaction).
  • 3. Pay transaction fees with ERC-20 tokens and sponsorship of users’ gas fees on your dapp.
  • 4. And a host of other applications.

How does it work under the hood?

This improvement has been in the works for a few years now, I suggest you read Vitalik’s post explaining it in detail.

There are five major components to Account Abstraction under ERC-4337: UserOperation, Bundler, EntryPoint, Aggregators, and Paymasters. Here are the official specifications.

  1. UserOperation: A new, special kind of operation that gets sent to a new mempool (a waiting zone to be picked up by nodes) called the “alt mempool”  —  a place where transactions go to be validated. This is an entirely separate mempool from the one used for processing transactions on the Ethereum mainnet. Firstly, you must understand that all transactions on the Ethereum network must be triggered and paid for by an Externally owned Account (EOA). Using a separate mempool lets users bypass these rules without affecting Ethereum’s underlying system.

  2. Bundlers: Nodes that bundle together UserOperations from the alt mempool, and send them to a Entry Point smart contract for them to be executed.

  3. Entry Point: A smart contract responsible for executing bundles of UserOperations that were submitted by bundlers.

  4. Aggregators: A smart contract responsible for executing bundles of UserOperations that were submitted by bundlers.

  5. Paymaster: A smart contract responsible for executing bundles of UserOperations that were submitted by bundlers.

Let's Get Started

What are we going to build?

We will create a dApp for minting NFTs. This application will allow users to create local wallets from passwords and will not require paying for gas fees or signing the NFT claim action. We will leverage a ThirdWeb smart contract for Smart Wallets and the NFT as well as their SDK for this and we will code our own frontend using NextJS and Typescript. So, recap 1) smart wallet contract, 2) nft contract, 3) minting dApp.

Before we begin, make sure you have installed Metamask. You can download it from here.

Since we are going to be deploying contracts to Goerli Testnet, we will need funding from a testnet faucet. Head over to any faucet and request some GoerliETH to your wallet.

Step 1: Smart Wallets Contract Launch

The first thing we'll do is create a factory contract, responsible for the creation of new smart wallet contracts. By using a factory, we can deploy new smart wallets for users on demand; simply by asking the factory to create a new one.

1. Go to ThirdWeb Explore page and scroll down to Smart Wallet (Beta).

2. Select Simple Wallet Factory smart contract, and click Deploy now.

3. Leave all default settings but change network to Goerli.

What we’re going to do with this factory is generate smart wallets for users under the hood. We’ll perform a two-step process to easily onboard users into the application:

  1. 1. Generate a new EOA wallet for the user and store it on their machine.

  2. 2. Generate a smart wallet for the user, using the wallet from the previous step’ signer as a valid signer for the smart wallet.

This way, the user will interact with our application from their generated smart wallet. By using the signer of the generated EOA to approve transactions, we can hide any prompts or approvals from the user.

Step 2: NFT Contract Launch

We will be launching our own NFT contract as well.

1. Go to ThirdWeb Explore page and scroll down to Popular.

2. Select NFT Drop contract and click Deploy now.

3. Fill in the Name, Description, Symbol and upload a square image. Remember to select Goerli network and click on Deploy now and make sure you have checked the option to add it to your dashboard!

Once the contract is deployed, we will be able to see it in our dashboard but we have a couple of more configurations to make. You see, we created a collection but now we need to prepare the metadata for the tokens that are going to be minted.

4. On the left menu, head over to "NFTs" and click on the button "Batch Upload" we will be uploading 100 metadata entries to create new NFTs under our collection. You can use our metadata file for this or create your own.

5. On the left menu, now go to "Claim Conditions" and click on "Add Phase" and make it public so we can all mint them.

Once you are done we are ready with our NFTs. We launched the collection contract, prepared the data for the next 100 mints and setup public the minting.


Step 3: dApp

Let's get ready for some coding. We are going to be using NextJS and Typescript along the ThirdWeb SDK.

1. From the ThirdWeb console, request a new API Key. Make sure your wallet is connected to the Goerli network.

2. We'll be creating a Next.js + TypeScript application with the thirdweb React SDK installed to add our web3 features and capabilities. To get started, create a new project with the SDK pre-configured by running the following command from your terminal:

npx thirdweb create app --evm --next --ts

3. Open your project and head over to _app.tsx file. Let's change the active chain to "goerli".

4. Add a supportedWallet property to ThirdWebProvider. This object contains your factory address created previously for the smart wallet and the thirdwebApiKey created.

5. In order to not have users pay for gas fees we will set the property gasless to true.

6. We also want our users not having to have their own wallets nor needing to remember a 24 word seed phrase so we are going to enable local wallet as well and have it stored securely in the user's device.

Notice I use images to avoid you copy pasting content and actully reflecting on the edition! 

7. Open index.tsx file. We are going to delete most of the content in the component and replace it with Web3Button from ThirdWeb SDK. This button will allow us to authenticate and also execute the function method "claim".

8. We are going to define a constant "contractAddress" with the address of our NFT contract in the goerli testnet we created previously.

9. Upon success we will create an alert, print the transaction receipt and also open 2 new tabs in the browser, one for the transaction in the explorer and a second one to view our minted item through Opensea platform viewer.

If everything went according to plan, you should see your transaction in the explorer and your newly minted asset on Opensea!. You view the live app here and the repository in github.

Resources and inspiration

https://blog.jarrodwatts.com/i-fixed-web3-onboarding
https://medium.com/infinitism/erc-4337-account-abstraction-without-ethereum-protocol-changes-d75c9d94dc4a
https://eips.ethereum.org/EIPS/eip-4337
https://thirdweb.com/explore
https://webstudio.so