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
- Sign in to your CDP account
- Navigate to Onchain Tools > Paymaster
- Select your network (Base or Base Sepolia) in the top right
- Copy your Paymaster & Bundler endpoint URL
- Under Configuration, add any contracts you want to sponsor to the allowlist
.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:Step 3: Configure Wagmi with Base Account
Create your Wagmi configuration using thebaseAccount 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’suseWriteContracts 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 withuseWriteContracts to send gasless transactions:
MintPage.tsx
Batch Multiple Calls
You can batch multiple contract calls into a single sponsored transaction:Production Considerations
Use a Paymaster Proxy
Never expose your Paymaster URL in client-side code. Create a backend proxy:api/paymaster/route.ts
Resources
- Base Account Wagmi Template — Complete example project
- Wagmi Experimental Hooks — Documentation for
useWriteContractsanduseCapabilities - Base Account SDK — Full SDK documentation
Troubleshooting
If you run into errors, check:- Paymaster Errors — Common error codes and solutions
- Troubleshooting Guide — Debugging tips for userOperations