Overview

Smart Accounts unlock the ability for developers to sponsor gas on their users’ transactions. With the CDP SDK, it’s simple to integrate any paymaster URL and cover gas costs for all transactions originating from your smart accounts.

You can refer to this guide on how to set up a CDP Paymaster. You could also use any provider of your choice.

Benefits:

  • Removes the friction of requiring users to hold ETH
  • Enables users to interact with your app immediately
  • Provides a more familiar Web2-like experience for new users
  • Allows you to subsidize or fully cover transaction costs for your users
  • Gives you control over which transactions you want to sponsor

Prerequisites

  • A Coinbase Developer Platform account
  • The following environment variables in your .env file:
CDP_API_KEY_ID=your_api_key_id
CDP_API_KEY_SECRET=your_api_key_secret
CDP_WALLET_SECRET=your_wallet_secret

Navigate to the CDP Portal to find or create your wallet secret, walletid, and client api key

All user operations on Base Sepolia are sponsored by default. For mainnet, you can specify a paymaster of your choice as follows:

    import dotenv from "dotenv";
    import { parseEther } from "viem";
    import { CdpClient } from "@coinbase/cdp-sdk";
    dotenv.config();

    const cdp = new CdpClient({
        apiKeyId: process.env.CDP_API_KEY_ID,
        apiKeySecret: process.env.CDP_API_KEY_SECRET,
        walletSecret: process.env.CDP_WALLET_SECRET,
      });

    const account = await cdp.evm.createAccount();

    const smartAccount = await cdp.evm.createSmartAccount({
      owner: account,
    });

    const userOperation = await cdp.evm.sendUserOperation({
      smartAccount: smartAccount,
      network: "base-sepolia",
      calls: [
        {
          to: "0x0000000000000000000000000000000000000000",
          value: parseEther("0"),
          data: "0x",
        },
      ],
      paymasterUrl: "https://some-paymaster-url.com",
    });

    console.log("User Operation Result:", userOperation);

You get up to $100 in free credits on CDP and you can apply for additional gas credits as you scale.

Common Issues

  • If transactions fail, verify your gas estimates
  • If paymaster fails, check your paymaster client and network configuration
  • Make sure your environment variables are properly set in your .env file
  • Verify you’re on the correct network before proceeding with transactions

Additional Resources