Skip to main content

Paymaster and Bundler QuickStart

This quickstart tutorial explains how to submit your first smart account transaction on Base Sepolia using Permissionless, with gas sponsorship from the Coinbase Developer Platform.

Prerequisites

node >= 14.0.0
npm >= 6.0.0

Submit smart account transaction

Get Base Node endpoint

How to Get a Base Node endpoint from the Coinbase Developer Platform

  1. Create an account or login at https://cloud.coinbase.com/.
  2. Navigate to the Base Node page.
  3. Enable Account Abstraction by clicking Claim Credits next to Paymaster & Bundler. You can leave the gas policy default values as-is.
  4. Switch to Base testnet (Sepolia) and copy your endpoint for later.
Expand for images and click to enlarge
Paymaster and Bundler - Claim Credits


Paymaster and Bundler - Gas Policy


Send Transaction

How to call the mint function of a Base Sepolia NFT contract (or contract of choice)

  1. In your terminal, create a directory called paymaster-tutorial and initialize a project using npm.
mkdir paymaster-tutorial
cd paymaster-tutorial
npm init es6
  1. Download permissionless.js and viem.
npm install permissionless
npm install viem
  1. Create a file called index.js, and add the following import statements:
import { http, createPublicClient, encodeFunctionData } from 'viem'  
import { baseSepolia } from 'viem/chains'
import { createSmartAccountClient, ENTRYPOINT_ADDRESS_V06 } from 'permissionless'
import { privateKeyToSimpleSmartAccount } from "permissionless/accounts"
import { createPimlicoPaymasterClient } from "permissionless/clients/pimlico";
  1. Create a smart account for the user. Here, we using a SimpleAccount with a private key as the signer.

    a. Create a new private key with Foundry.

    b. Install Foundry: curl -L https://foundry.paradigm.xyz | bash

    c. Generate a new key pair: cast wallet new.

// Set this to the Base Node RPC URL from Step 1.
const rpcUrl = "YOUR RPC URL"

const publicClient = createPublicClient({
transport: http(rpcUrl),
});

const simpleAccount = await privateKeyToSimpleSmartAccount(publicClient, {
// Set this to your private key
privateKey: "YOUR PRIVATE KEY HERE",
factoryAddress: "0x9406Cc6185a346906296840746125a0E44976454",
entryPoint: ENTRYPOINT_ADDRESS_V06,
})
  1. Create the Coinbase Developer Platform Paymaster and plug it into the smart account client.
const cloudPaymaster = createPimlicoPaymasterClient({
chain: baseSepolia,
transport: http(rpcUrl),
entryPoint: ENTRYPOINT_ADDRESS_V06,
})

const smartAccountClient = createSmartAccountClient({
account: simpleAccount,
chain: baseSepolia,
bundlerTransport: http(rpcUrl),
// IMPORTANT: Set up the Cloud Paymaster to sponsor your transaction
middleware: {
sponsorUserOperation: cloudPaymaster.sponsorUserOperation,
}
});

  1. Send the sponsored user transaction!

    We are calling the mint function of a Base Sepolia NFT contract. To replace the contract with your own, modify the arguments to encodeFunctionData.

const abi = [{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint16","name":"item","type":"uint16"}],"name":"mintTo","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"}];

const callData = encodeFunctionData({
abi: abi,
functionName: "mintTo",
args: [smartAccountClient.account.address, 0],
});

const txHash = await smartAccountClient.sendTransaction({
account: smartAccountClient.account,
to: "0x66519FCAee1Ed65bc9e0aCc25cCD900668D3eD49",
data: callData,
value: 0n,
});
console.log("✅ Transaction successfully sponsored!")
console.log(`🔍 View on Etherscan: https://sepolia.basescan.org/tx/${txHash}`);
node index.js

Examples

  • See examples with other SDKs in our Paymaster repo and a full application using sponsored transactions in the Build Onchain Apps website.

  • Still need help? Join the Developer Platform Discord and reach out in #base-node.

Was this helpful?