Executing Token Swap on Uniswap V3 with Pimlico's ERC20 Paymaster & Verifying Paymster using Alto Bundler
Pimlico Plugin tailored for Account Abstraction (AA) with a performant ERC-4337 bundler and Pimlico Paymasters.
Introduction
This tutorial guides you through integrating Pimlico Paymaster with their ERC-4337 compatible Alto bundler for account abstraction in blockchain applications using the Pimlico plugin. Pimlico Alto simplifies bundling user operations into transactions and submitting them to the blockchain via standard JSON-RPC requests. It supports permissionless.js, enabling seamless Web3 application development and testing. Additionally it also supports Paymaster services allowing the users to perform gasless transactions, and paying for gas in ERC20s instead
Why Test Pimlico AA with BuildBear Sandbox?
Seamless Integration
Pimlico Plugin is designed for effortless integration with BuildBear Sandboxes, making it easy to experiment with Account Abstraction (AA) features.
Permissionless.js Support
- High-level API for managing ERC-4337 smart accounts, bundlers, and paymasters.
- Built on Viem for modularity and extensibility.
JSON-RPC Support for Bundler
Interact with the bundler using standard methods:
eth_sendUserOperation
eth_estimateUserOperationGas
eth_getUserOperationReceipt
eth_getUserOperationByHash
eth_supportedEntryPoints
pimlico_getUserOperationGasPrice
pimlico_getUserOperationStatus
ERC20 Paymaster Support
Choose from a list of supported tokens to pay for transactions in ERC20 instead of native tokens.
Verifying Paymaster Support
The gasless paymaster (native-gas sponsorship) is also supported.
Unlocked Faucets
BuildBear provides unlimited access to native and ERC-20 tokens, ensuring smooth development and testing.
Step-by-Step Video Tutorial
Watch our video tutorial for a step-by-step guide on setting up and using the Pimlico Paymaster using BuildBear's Pimlico Plugin.
Step 1: Setting Up Pimlico
1. Create a BuildBear Sandbox
- Navigate to BuildBear and create a new Sandbox or use an existing one.
- Open the Plugins tab in your Sandbox dashboard.
2. Install the Pimlico Plugin
- Locate Pimlico in the plugin marketplace.
- Click Install to add it to your environment.
- Verify installation in the Installed Plugins tab.
3. Retrieve the RPC URL
- Open your BuildBear Sandbox dashboard.
- Copy the RPC URL, which also serves as the Pimlico Client API endpoint.
4. Install Dependencies
Ensure all necessary dependencies are installed. Example package.json
:
Step 2: Configuring BuildBear
Note: For this walkthrough, use a sandbox forked from Polygon Mainnet
1. Define the Sandbox URL
2. Set Up BuildBear Sandbox Network
3. Generate a Private Key
4. Set Up Public Client
Step 3: Configuring Pimlico Client & Smart Accounts
1. Set Up Pimlico Client
2. Create Smart Account & Client
Step 4: Funding & Executing Transactions
1. Check Account Balance
2. Fund Smart Account
Native Token Faucet
ERC Token Faucet
3. Setup Helper Functions
4. Initialize Swap Params & Estimate Cost
5. Send Transaction
ERC20 Paymaster
Expand to See the Complete Tutorial Script
Verifying Paymaster Mode (Native Gas)
When you remove the ERC-20 approval call and omit the paymasterContext
from your sendUserOperation
payload, Pimlico automatically switches into Verifying Paymaster mode. In this mode:
- No
paymasterContext
field is required. - Pimlico covers the gas on your behalf under the hood.
Just call:
Execute the script with npm start
and the swap should go through producing the following output:
Step 5: Debugging and Deep Dive into UserOp with Sentio
Clicking on View On Sentio will open a Sentio debugger for the transaction, where you can observe:
1. Fund Flow
- Depicts the flow of funds among different contracts and their order of execution
2. Call Trace
- Shows the entire call trace for the transaction, including:
- Contract calls
- Functions called within the contract
- Inputs and outputs
3. Call Graph
- Visual graph showing top-level overview of contract interactions
4. Gas Profiler
- Displays gas usage per function and gas metrics:
- Limits, actual usage, initial gas
5. Debugging With Sentio
- Access the Debugger Tab:
- View inputs, gas metrics & return values for every call
- Contracts Tab:
- Deeper inspection of smart contracts and functions
- Events Tab:
- All event emissions from the transaction
- State Tab:
- State of funds before & after the transaction
Conclusion
By following this tutorial, you have successfully:
- Set up Pimlico on BuildBear
- Configured a smart account using
permissionless.js
- Set up ERC20 Paymaster and Verifying Paymaster with Pimlico Client & Alto Bundler
- Funded the smart account using BuildBear faucets
- Executed a UserOperation to swap tokens on Uniswap V3 using ERC20 gas payments (DAI)
For full code and demos, check out the GitHub repository!