ERC-4337 is the Ethereum community's first attempt to simplify the wallet experience for users coming from a more familiar "web2 way of life". E-mail login and authorisation is a de-facto - if not, almost a standard across mobile/web applications. Web3 "sign-in" and authorisation is based on private keys that has properties that make it impenetrable (until now), but are also known to be unwieldy, hard to manage making them cumbersome.
This code has been majorly influenced by eth-infinitism's example implementation of ERC-4337.
The Toad Relay is currently a component residing with the Bundler but will soon be extracted as a separate component in the near future. Refer to the Bundler section for now.
Bundler is a component being built as per the ERC4337 (Account Abstraction via Entry Point Contract specification). Bundler is a Rust based implementation that exposes REST APIs and also acts as a Relayer.
It uses Actix web framework to expose REST APIs.
MSRV: rustc 1.71.0 (8ede3aae2 2023-07-12)
Smart Contract Wallet (SCW) contract is deployed for every user that's onboarded on the Toad system
Smart Contract Factory deploys SCWs for users
eth-infinitism's reference implementation of the Entry Point spec for local testing.
Reference implementation of Token Paymaster
Reference implementation of Verifying Paymaster
NOTE: The following instructions have been tested on macOS 13.5.2. Support for more platforms will be added.
If you are running this project on localhost, you need to have a local node running with the contracts deployed. We use Foundry's Anvil to run a local node for development and testing:
- Follow the instructions in the foundry installation guide to set up foundry tool kit
- Navigate to the
contracts/
folder - To install all the contract dependencies, run
bash foundry_setup.sh
- Populate the
contracts/.env
with the following valuesTheRPC_URL=http://localhost:8545 PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 CHAIN_ID=31337 ENTRYPOINT_SALT=1 SIMPLE_ACCOUNT_FACTORY_SALT=2 TEST_ERC20_SALT=3 VERIFYING_PAYMASTER_SALT=4
PRIVATE_KEY
is the default key generated by anvil. The salt values can be changed if required. This will affect the addresses at which the contracts are deployed. - To start a local anvil node and deploy the contracts, run
bash script/deploy_local.sh
On successful deployment, you can find the deployed contract addresses, signer/owner
address and a key
. Use this info to populate the bundler/.env
and bundler/config/*.toml
files, as directed in the following section
NOTE: In case an instance of anvil
is running and the contracts already deployed, stop the instance using
pkill -f anvil
- Set up a postgres database
- Navigate to
bundler/.env.example
and set the environment variables mentioned there (using the export command)- By default, the server uses "Development.toml" as the config file. If you want to use a different config file, set the
RUN_ENV
environment variable to the path of the config file.RUN_ENV
can be one of:- Development
- Production
- Staging
- If your RUN_ENV is "Development", set INFURA_KEY to an empty string
- Use
key
obtained in the previous section to populateWALLET_PRIVATE_KEY
andVERIFYING_PAYMASTER_PRIVATE_KEY
- By default, the server uses "Development.toml" as the config file. If you want to use a different config file, set the
- Create a copy of
config/Staging.toml
and rename it asconfig/Development.toml
. Set the values in the config file as per your requirements.cp config/Staging.toml config/Development.toml
- To initialise the DB tables, run
cargo sqlx migrate run --database-url $DATABASE_URL
- Run
cargo run
NOTE: If there are any changes in the schema or the queries, run
cargo sqlx prepare --database-url $DATABASE_URL
and add the generated files or the github workflow will fail. Files will be generated under bundler/.sqlx
The project does not come with a "Production.toml", but you can create one and use it. The config file should be in the same format as "Development.toml".
A Foundry project for deployment and testing of the ERC-4337 contracts
- git clone https://github.com/roverxio/toadplatform
- cd
contracts
- execute
foundry_setup.sh
- Build
forge build
- Testing
forge test
- To deploy the contracts execute:
deploy_local.sh
All the dependent libraries are under contracts/lib
directory, we have bash script (contracts/foundry_setup.sh
) which will install all the dependencies required
- Forge Std (default)
- Openzeppelin Contracts (v4.9.3)
- Uniswap/v3-periphery (v1.3.0)
- Uniswap/v3-core (v1.0.0)
All the test case are referred from account-abstractions code from eth-infinitism. Test cases from eth-infinitism's code base have been ported using forge (the tool of our choice). Some test cases that required RPC calls are yet to be ported.