Before you begin, select the version of the Circle Paymaster that you want to
build with.
- Paymaster v0.7
- Paymaster v0.8
This guide walks you through the process of:Create a new Edit the The
- Setting up a smart account and checking its USDC balance
- Configuring the Circle Paymaster v0.7 to pay for gas with USDC
- Connecting to a bundler and submitting a user operation
Note: Throughout this tutorial, each snippet lists any new imports above
the relevant code. You should add the new imports to the top of the file and
merge with other imports from the same module. You can add the rest of the
code inline.
Prerequisites
Before you start building the sample app to pay for gas fees in USDC, ensure that Node.js and npm are installed. You can download and install Node.js directly, or use a version manager like nvm. The npm binary comes with Node.js.Part 1: Set up a smart account
The following steps cover the steps required to set up your environment and initialize a new smart account.1.1. Set up your development environment
Create a new project, set the package type tomodule, and install the
necessary dependencies.Shell
.env file.Shell
.env file and add the following variables, replacing
{YOUR_PRIVATE_KEY} and {RECIPIENT_ADDRESS} with your own values:RECIPIENT_ADDRESS is the destination address for the example USDC
transfer.1.2. Initialize clients and smart account
Create a file calledindex.js and add the following code to set up the
necessary clients and account:Javascript
1.3. Check the USDC balance
Check the smart account’s USDC balance using the following code:Javascript
Part 2: Configure the Paymaster
The Circle Paymaster requires an allowance to spend USDC on behalf of the smart account.2.1. Implement the permit
A USDC allowance is required for the paymaster to be able to withdraw USDC from the account to pay for fees. A signed permit can be used to set the paymaster’s allowance without submitting a separate transaction.Create a new file calledpermit.js with the following code to sign EIP-2612
permits:Javascript
2.2. Set up Circle Paymaster
In theindex.js file, use the Circle permit implementation to build paymaster
data:Javascript
Part 3: Submit a user operation
Once the paymaster is configured, you can connect to a bundler and submit a user operation to transfer USDC.3.1. Connect to the bundler
Inindex.js, set up the bundler client with the following code:Javascript
3.2. Submit the user operation
Finally, submit a user operation to transfer USDC, using the paymaster to pay for the network fee in USDC. Inindex.js add the following code:Javascript