Skip to main content
Before you begin, select the version of the Circle Paymaster that you want to build with.
This guide walks you through the process of:
  1. Setting up a smart account and checking its USDC balance
  2. Configuring the Circle Paymaster v0.7 to pay for gas with USDC
  3. Connecting to a bundler and submitting a user operation
This quickstart shows you how you can integrate Circle Paymaster into your app to simplify network fee management for your users.
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 to module, and install the necessary dependencies.
Shell
Create a new .env file.
Shell
Edit the .env file and add the following variables, replacing {YOUR_PRIVATE_KEY} and {RECIPIENT_ADDRESS} with your own values:
The RECIPIENT_ADDRESS is the destination address for the example USDC transfer.

1.2. Initialize clients and smart account

Create a file called index.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 called permit.js with the following code to sign EIP-2612 permits:
JavaScript

2.2. Set up Circle Paymaster

In the index.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

In index.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. In index.js add the following code:
JavaScript

Next steps

The above example demonstrates how to pay for a transaction using only USDC. You can review the transaction in an explorer to verify the details and see the USDC transfers that occurred during the transaction. Remember that you need to use the transaction hash from the bundler, not the user operation hash in the explorer. You can also view more details about the user operation by searching for the user operation hash in a user op explorer on the appropriate network.