In this tutorial series, you'll create a Smart Account and send tokens using ERC-4337. The example app addresses how to create ERC-4337 accounts and build simple User Operation. In the example app, users can send tokens from the command line.
If you are new to account abstraction, we recommend the introduction to account abstraction and an overview of ERC-4337.
Clone the ERC-4337 Examples repository to download the scripts. This example is a basic command-line wallet application.
git clone https://github.com/stackup-wallet/erc-4337-examples.git
This example uses the userop.js library for building user operations. You can think of it like ethers.js but for ERC-4337. Install it, and all other dependencies.
You can now initialize your local configuration.
yarn run init
A config.json file will be created. The file will look like this:
|URL of an ERC-4337 bundler and node
|Private key that can sign transactions for the Smart Account
|Address of the EntryPoint contract
|Address of the factory that will create the account
|URL of the Paymaster service you are using and context (optional)
In this quick start you will only need to set the
You can create a free bundler instance at app.stackup.sh.
Create an account and select the Polygon Mumbai network for the instance and ensure the version is set to 0.6.x. Once the instance is created, click the copy icon to view the instance URL. Copy it and replace the default
rpcUrl in config.json with the generated address.
You can leave the
paymaster blank. If you want to try a paymaster, see the Paymaster Example.
Create an account using the factory simpleAccountFactory defined in the configuration file.
yarn run simpleAccount address
An address will be returned. At this point, the Smart Account has not been deployed. ERC-4337 account addresses are deterministic, so you don't need to deploy the contract to know its address.
You will now need to deposit the native token of the blockchain you are using into your new Smart Account. Since this tutorial uses the Polygon Mumbai testnet, you will deposit MATIC into the account on Mumbai.
Navigate to a faucet, such as https://faucet.polygon.technology/. Enter the account address from step 4 and claim the testnet token.
Faucets do not send directly to smart contracts. You must deposit tokens from the faucet before your first transaction.
simpleAccount transfer command allows you to transfer the native token from the smart contract account to any address. It will create a User Operation, sign it, and send it to the Bundler:
yarn run simpleAccount transfer --to <address> --amount <eth>
You can then find the transaction using a block explorer like polygonscan!
Stackup's infrastructure is compatible with any ERC-4337 SDK, Smart Account, and Paymaster. You can find some of the leading ERC-4337 developer SDKs here.
Additionally Stackup maintains userop.js, an MIT-licensed library for creating User Operations that is the backbone of many of these SDKs. If you can't find an SDK that meets all of your needs, we recommend building directly from this library or extending an open source SDK using userop.js.
You may be interested in a Discovery package.
During the quickstart you may encounter these common error messages.
AA21 didn't pay prefund is an error from the bundler that indicates that the account does not have enough funds. This usually means that you did not fund your account in step 5.
400 bad request: invalid tracer value or
This method is not whitelisted are responses that you may get if you are running your own bundler locally and using an external node provider. Most node providers do not support the custom tracing that bundlers need. Either run your own local node or use Stackup's bundler service.
entryPoint: Implementation not supported means that the bundler being used for the transaction does not support the selected Entry Point. If you are using a Stackup bundler, we recommend setting your bundler instance to the latest version and the canonical Entry Point contract.
Updated 4 months ago