wagmi.ts
, adding Base-specific information, configuring the Coinbase Developer Platform (CDP), and implementing Wagmi’s experimental hooks for onchain actions.
Initial setup: Configure CDP Account
Create a new CDP account or sign in to your existing account.Obtain Paymaster & Bundler Endpoint
In your CDP dashboard, navigate to Onchain Tools > Paymaster. Then click theConfiguration
tab.
Select the chain, Base
or Base Sepolia
, you’d like to sponsor transactions on. Then copy the RPC URL in the Paymaster & Bundler endpoint section.
SecurityThis guide uses environment variables to store the Paymaster & Bundler endpoint obtained from cdp.portal.coinbase.com. The most secure way to do this is by using a proxy. For the purposes of this guide, the endpoint is hardcoded into our project file. For production, we highly recommend using a proxy service.
.env
file as NEXT_PUBLIC_CDP_PAYMASTER
or set up a proxy service for production applications.
Whitelist Contracts
In the Contract allowlist section, add the smart contract addresses you want to interact with using the Base Paymaster. Give each contract a name and be sure to include the specific functions as well as the contract address. Then clickAdd
.
WalletConnect Project IDBase Wallet (FKA Coinbase Smart Wallet) requires a WalletConnect project ID to work. If you don’t have one, please obtain one (free) from their website.
Add Base to Wagmi configuration
Open your project’swagmi.ts
to configure your project to support the Base network, WalletConnect, and Coinbase Wallet connectors:
wagmi.ts:
Implement Wagmi Hooks
For the onchain actions (minting, etc.) of your application, use Wagmi’s experimental hooks to manage wallet connection, check for paymaster capabilities, and execute onchain actions with you whitelisted contracts.useCapabilities
: Retrieves the capabilities supported by the connected wallet, such aspaymasterService
for gasless transactions.useWriteContracts
: Executes onchain write actions, here used to call themintTo
function on the NFT contract.
mint/page.tsx