A collection of example scripts for working with ERC-4337. For an overview on the EIP and account abstraction, see our docs here.
All scripts in this repository is built using @account-abstraction/sdk. The implementation of all the following commands are located in the scripts directory.
Clone this repo into your local environment:
git clone git@github.com:stackup-wallet/erc-4337-examples.git
Install dependencies:
yarn install
These config values will be used for all documented commands.
yarn run init
Default value is set to http://localhost:4337
.
All UserOperations are required to be sent to a bundler. This field specifies the URL for the bundler you want to use.
You can run a self-hosted instance with stackup-bundler. Fully managed instances are also available. If you would like one setup, come talk to us!
Default value is set to https://rpc-mumbai.maticvigil.com/
.
This is a standard RPC URL for an ethereum node. By default it uses the public RPC for Polygon mumbai testnet. You can change this to any network you like.
Default value is randomly generated with ethers.js.
All UserOperations have a signature
field which smart contract accounts will use to validate transactions. This key will be used to sign all UserOperations and set as the owner for the smart contract account.
Default value is set to 0x78d4f01f56b982a3B03C4E127A5D3aFa8EBee686
.
This is address of the singleton EntryPoint contract. It is the same on all networks.
Default value is set to 0xe19E9755942BB0bD0cCCCe25B1742596b8A8250b
.
This is factory address for deploying SimpleAccount.sol. It is the same on all networks and allows us to generate deterministic addresses.
Once you have an environment setup, these commands can be used for running the example scripts.
The location of each script mimics the command structure. For example yarn run simpleAccount:address
will be located in scripts/simpleAccount/address.ts
Scripts for managing accounts based on SimpleAccount.sol.
Smart contract account addresses can be deterministically generated. Use this command to get your account address based on the signingKey
set in your config.json
.
The account will be automatically deployed on the first transaction.
yarn run simpleAccount:address
Before executing a transfer, make sure to deposit some ETH to the address generated by the simpleAccount:address
command.
yarn run simpleAccount:transfer <recipient-address> <eth-amount>
Make sure the address generated by simpleAccount:address
has enough specified tokens to execute the transfer.
This command does not use a paymaster so make sure to also have enough ETH to pay gas fees.
yarn run simpleAccount:erc20Transfer <token-address> <recipient-address> <token-amount>
This example shows how we can do multiple atomic ETH transfers in a single transaction.
# recipient-addresses is comma separated.
# e.g. 0x123..abc,0x456...def
yarn run simpleAccount:batchTransfer <recipient-addresses> <eth-amount>
Similar to simpleAccount:batchTransfer
, we can also do multiple atomic contract interactions in a single transaction. This example shows us how with an ERC-20 token.
# recipient-addresses is comma separated.
# e.g. 0x123..abc,0x456...def
yarn run simpleAccount:batchErc20Transfer <token-address> <recipient-addresses> <token-amount>
Distributed under the MIT License. See LICENSE for more information.
Feel free to direct any technical related questions to the dev-hub
channel in the Stackup Discord.