Skip to main content

Quickstart: Submit your First Smart Account Transaction

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

Prerequisites

node >= 14.0.0
npm >= 6.0.0

Getting an Endpoint on Base Sepolia

How to Get a Base Node endpoint on Base testnet (Sepolia) from CDP

  1. Create a new CDP account or sign in to your exsiting account.
  2. Navigate to Paymaster and verify the default gas policy values (which you can change later).
  3. Switch to Base testnet (Sepolia) in the top right of the configuration.
  4. Copy your endpoint to use later.
Expand for images and click to enlarge
Bundler & Paymaster - Claim Credits


Bundler & Paymaster - Gas Policy


Sending a Transaction

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

Initialize your project

  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

Download dependencies

  1. Download permissionless.js and viem.
npm install permissionless
npm install viem

Add import statements

  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";

Create a smart account

  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,
});

Create the Paymaster

  1. Create 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 Cloud Paymaster to sponsor your transaction
middleware: {
sponsorUserOperation: cloudPaymaster.sponsorUserOperation,
},
});

Send the sponsored transaction

  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

Go to the repo paymaster-bundler-examples for examples with other SDKs and a full application using sponsored transactions in the Build Onchain Apps website.

Was this helpful?