Skip to main content
This guide covers how to integrate CDP Paymaster for gasless transactions in a Wagmi project using the Base Account SDK. You’ll configure Wagmi with the baseAccount connector and use Wagmi’s hooks to execute sponsored transactions.
This guide uses the Base Account SDK which provides a streamlined connector for Wagmi. For CDP user wallets integration, see the Quickstart.

Prerequisites

  • A CDP account with Paymaster enabled
  • Node.js 22+ and a package manager (npm, pnpm, yarn, or bun)
  • Basic familiarity with React and Wagmi

Step 1: Set Up CDP Paymaster

  1. Sign in to your CDP account
  2. Navigate to Onchain Tools > Paymaster
  3. Select your network (Base or Base Sepolia) in the top right
  4. Copy your Paymaster & Bundler endpoint URL
  5. Under Configuration, add any contracts you want to sponsor to the allowlist
Security: Your Paymaster endpoint should not be exposed in client-side code. For production, use a proxy service to protect your API key.
Add the endpoint to your environment:
.env

Step 2: Install Dependencies

New Wagmi Project

Create a new Wagmi project and override the Base Account SDK version:

Existing Project

Add the required packages and override:
If you’ve installed previously, delete node_modules and package-lock.json then run a fresh install to ensure overrides are applied.

Step 3: Configure Wagmi with Base Account

Create your Wagmi configuration using the baseAccount connector:
wagmi.ts

Step 4: Set Up Providers

Wrap your application with the Wagmi and QueryClient providers:
providers.tsx

Step 5: Send Sponsored Transactions

Use Wagmi’s useWriteContracts hook with paymaster capabilities to execute gasless transactions.

Check Paymaster Support

First, check if the connected wallet supports paymaster services:
usePaymasterCapabilities.ts

Execute Sponsored Transaction

Use the capabilities with useWriteContracts to send gasless transactions:
MintPage.tsx

Batch Multiple Calls

You can batch multiple contract calls into a single sponsored transaction:
All calls execute atomically — if any call fails, the entire transaction reverts.

Production Considerations

Use a Paymaster Proxy

Never expose your Paymaster URL in client-side code. Create a backend proxy:
api/paymaster/route.ts
Then use your proxy URL in the capabilities:
See the Paymaster Proxy Guide for more details.

Resources

Troubleshooting

If you run into errors, check: