Skip to main content

ERC-7677 Paymaster Methods

The policy service speaks ERC-7677, the paymaster web-service standard. Two JSON-RPC methods, pm_getPaymasterStubData and pm_getPaymasterData, are what Privy's smart-wallet client and viem's paymaster client call. Read this page to understand how the two differ, what to put in context, what the responses look like and how to build the requests with the SDK.

Endpoint POST /v2/paymaster/<token>, hosted at https://paymaster.pepeunchained.com. The URL always embeds a token, so there is no tokenless default; PEPU_PAYMASTER_URL holds the complete URL. The v1 route POST /paymaster/<appToken> is retired. Local default: http://localhost:8788.

Endpoints​

VersionPathCredential in the URL
v1POST {PEPU_PAYMASTER_URL}/paymaster/<appToken> (and OPTIONS for CORS), retiredThe app's raw API key. Treat the whole URL as a secret
v2POST https://paymaster.pepeunchained.com/v2/paymaster/<token> (and OPTIONS)A project's client token ppt_... (browser-safe, origin-bound) or server key ppk_... (secret)
Privy's dashboard "Paymaster URL" field is a bare URL with no separate header or secret field, which is why the credential travels in the path. See Credential Matrix.

A ppt_ client token works only from the project's allowed origins; with none set, or from another origin, the service answers project_origin_not_allowed. If Privy calls from its own servers, use the ppk_ server key and keep it secret. The free tier needs context.privyAccessToken from PEPU's own Privy app; a third-party app's token is ignored for billing, and the dashboard URL cannot attach one, so the free tier is not reachable from the Smart Wallets dashboard. Privy's dashboard "Paymaster URL" field is a bare URL with no separate header or secret field, which is why the credential travels in the path. See Credential Matrix.

Both routes accept a single request or a JSON-RPC batch array (v2 handles at most 20 per batch). Only these two methods exist; anything else returns -32601. pm_sponsorUserOperation is not implemented.

Request shape​

Both methods take positional params [userOperation, entryPoint, chainId, context?]:

ParamValue
userOperationUnpacked v0.7 UserOperation
entryPoint0x0000000071727De22E5E9d8BAf0edAc6f37da032 (v0.7 only)
chainId"0x17dcd" (97741). A decimal number or string is also accepted
contextOptional object. v1 accepts and ignores it. v2 reads privyAccessToken

Stub versus data semantics​

pm_getPaymasterStubDatapm_getPaymasterData
When it is calledBefore gas estimationRight before submission to the bundler
PurposeFields that let eth_estimateUserOperationGas simulate without revertingThe real, signed approval
Runs the policy engineNo. No cap consumed, no audit row, nothing recordedYes. Every cap, allowlist, budget and the signing step
AuthenticatedNo, by spec. The URL credential is not resolved for the stub (v1). Unknown credentials get the same stubYes
SignatureA real ECDSA signature from a throwaway key over a zero hash: well formed, never authorisedFrom the policy signer
isFinalfalsenot returned

Stub data is unauthenticated by design, and that is not a hole. ERC-7677 defines the stub call purely as a gas-estimation aid and draws the authorisation line at pm_getPaymasterData. The stub carries a dummy signature that the contract treats as an unauthorised signer, so using it on chain fails cleanly (sigFailed), never pays. The only cost of a bad credential is that you learn about it at the second call instead of the first. In v2 the stub carries the project's sponsor id if the URL token resolves to an active project, otherwise the free pool id, in the real 97-byte layout so preVerificationGas estimates match.

The dummy signature must be well formed​

If you estimate without paymaster fields, EntryPoint demands the sender's own prefund and a zero-balance account fails with AA21 didn't pay prefund. If you attach a signature-shaped blob that is not a valid ECDSA signature, the contract's recovery reverts instead of failing closed. That is why the service returns a real signature from a disposable key. Use the stub fields exactly as returned.

pm_getPaymasterStubData​

Request:

{
"jsonrpc": "2.0",
"id": 1,
"method": "pm_getPaymasterStubData",
"params": [
{
"sender": "0x…",
"nonce": "0x0",
"callData": "0x…",
"callGasLimit": "0x0",
"verificationGasLimit": "0x0",
"preVerificationGas": "0x0",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0"
},
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
"0x17dcd"
]
}

Only sender is validated for the stub; gas fields may be placeholders.

Response:

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"paymaster": "0xdb28528C9399C33c9A0297E8A62F39145acbC30D",
"paymasterData": "0x…",
"paymasterVerificationGasLimit": "0x…",
"paymasterPostOpGasLimit": "0x…",
"isFinal": false
}
}

For v1 (retired) the paymaster was the v1 contract and paymasterData is mode(1)=0x00 ‖ validUntil(6) ‖ validAfter(6) ‖ signature(65). For v2 the paymaster is the v2 contract and paymasterData is mode(1)=0x02 ‖ validUntil(6) ‖ validAfter(6) ‖ sponsorId(32) ‖ signature(65). You do not need to build these yourself.

pm_getPaymasterData​

Request: the same shape with the real, estimated gas fields filled in. For v2 add context when the free tier may be used:

{
"jsonrpc": "2.0",
"id": 2,
"method": "pm_getPaymasterData",
"params": [
{ "sender": "0x…", "nonce": "0x…", "factory": "0x…", "factoryData": "0x…", "callData": "0x…",
"callGasLimit": "0x…", "verificationGasLimit": "0x…", "preVerificationGas": "0x…",
"maxFeePerGas": "0x…", "maxPriorityFeePerGas": "0x…" },
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
"0x17dcd",
{ "privyAccessToken": "<the user's Privy access token>" }
]
}

Success:

{
"jsonrpc": "2.0",
"id": 2,
"result": {
"paymaster": "0x…",
"paymasterData": "0x…",
"paymasterVerificationGasLimit": "0x…",
"paymasterPostOpGasLimit": "0x…"
}
}

The approval is valid for a short window: 90 seconds on v1 (VALIDITY_WINDOW_SECONDS), 60 seconds on v2. A signature that sits unsubmitted past validUntil is rejected by EntryPoint. If you hit -32503 or AA32, ask for fresh paymaster data.

Idempotency: duplicate calls are expected​

Privy's smart-wallet client can run its prepare flow twice in parallel, producing two pm_getPaymasterData calls for the same UserOperation 10 to 300 ms apart. The policy service de-duplicates by userOpHash: if a live (unexpired, not voided) approval already exists for that hash, the second call skips the cap checks and the cost booking and returns a fresh signature for the same hash, so the spend is booked once. v2 also treats a re-request for the same (sponsor, sender, nonce) as a replacement of the earlier unexecuted approval, so retries never stack reservations (a smaller re-request keeps the earlier, larger reservation live until its signature expires). Design your own client to be safe to call twice, and do not treat a repeat as a new spend.

Context fields​

FieldVersionMeaning
privyAccessTokenv2The user's verified Privy access token. Required for the free tier; without it the free tier is denied with free_tier_identity_required. A project's own budget does not need it (unless the project turned on requireIdentity)
anything elsebothAccepted and ignored

buildPaymasterContext from the SDK drops undefined entries and rejects values that do not survive JSON (bigint, function, symbol).

Errors​

JSON-RPC errors use the standard envelope. Sponsorship denials carry the machine-readable reason in error.data.reason (v2 also adds detail, the reason per tier tried).

error.codeMeaning
-32700Parse error
-32600Invalid request
-32601Method not found (only the two methods above exist)
-32602Invalid params: bad entry point, wrong chain, malformed UserOperation
-32603Internal error
-32000Sponsorship denied. error.data.reason is one of the denial reasons
-32001New-account deployment (factory/factoryData) is disabled on this endpoint (PAYMASTER_RPC_ALLOW_ACCOUNT_DEPLOYMENT is false). Default is allowed, because a first transaction needs it

Example denial:

{
"jsonrpc": "2.0",
"id": 2,
"error": {
"code": -32000,
"message": "Sponsorship denied: …",
"data": { "reason": "user_hourly_spend_cap_exceeded" }
}
}

The SDK maps reasons to typed errors: paymasterReasonToError and mapPaymasterReason from @pepu-chain/sdk/paymaster. See Error Reference.

CORS​

The route is called straight from browsers, so it answers OPTIONS itself. By default it allows any origin (Access-Control-Allow-Origin: *); v1 narrows that with PAYMASTER_RPC_ALLOWED_ORIGINS. That is a browser speed bump only, not authentication. v2 binds the project to allowed origins separately, per client token, inside the engine.

Using the SDK builders​

import {
buildPaymasterContext,
buildPaymasterDataRequest,
buildPaymasterStubDataRequest,
} from "@pepu-chain/sdk";
import { buildErc7677Url } from "@pepu-chain/sdk/paymaster";

const url = buildErc7677Url({
baseUrl: "https://paymaster.pepeunchained.com", // hosted base; http://localhost:8788 locally
token: process.env.PEPU_CLIENT_TOKEN!, // a ppt_ client token, never a ppk_ server key in a browser
version: 2, // v2 serves /v2/paymaster/<token>; use 1 for /paymaster/<token>
});

const context = buildPaymasterContext({ privyAccessToken });
const stubRequest = buildPaymasterStubDataRequest({ userOperation, context });
const dataRequest = buildPaymasterDataRequest({ userOperation, context });

Both builders default the EntryPoint to the registry's v0.7 address and the chain to 97741. buildErc7677Url refuses a ppk_ server key in a browser because the URL would embed the secret. In practice, Privy or viem makes these calls once you give them the URL; reach for the builders when debugging or writing a custom client. See /paymaster.

Common failures​

SymptomCauseFix
invalid params: entryPoint ... not supportedSent a v0.6 EntryPointUse 0x0000000071727De22E5E9d8BAf0edAc6f37da032
invalid params: chainIdWrong chain, or a typo such as 977210x17dcd (97741)
-32000 with invalid_or_expired_tokenMissing, expired or unverifiable Privy tokenSend a fresh token
-32000 with unknown_or_invalid_app_credentialThe credential in the URL is unknown or revokedCheck the URL; rotate if a key leaked
Works in curl, fails in the browserOrigin not allowed for this client token, or CORSAdd the origin to the project's allowedOrigins; see REST API v2
AA33 reverted at the bundlerApproval expired, or (v2) the bundler executor is not allowlistedRequest fresh data; use the PEPU bundler
First sponsored transaction denied on capPer-user cap smaller than the one-time account deployment (about 12 PEPU worst case)Size caps above it. See Policy, Caps and the Circuit Breaker