Skip to content

Sign a userOperation for Paymaster sponsorization

Category: User Operations

Description: Sends a partial ERC-4337 userOperation (a userOp without paymasterAndData and signature) to the backend, that crafts the paymasterAndData field of the userOp and sends it back signed to the caller. (Request type IUserOperation)

Type: POST

URL: /sign-paymaster-op

Body Params (IUserOperation)

NameTypeRequired?Description
senderstringyesThe address of the sender smart contract wallet
noncebigNumberishyesThe nonce of the sender smart contract wallet
initCodebytesLikeyesThe init code of the sender smart contract wallet
callDatabytesLikeyesThe data to be sent to the sender smart contract account during execution
callGasLimitbigNumberishyesThe gas limit for the execution of the callData
verificationGasLimitbigNumberishyesThe gas limit for the verification of the signature and the nonce of the userOperation
preVerificationGasbigNumberishyesThe gas limit for all the operations before the verification of the signature and the nonce of the userOperation
maxFeePerGasbigNumberishyesThe maximum fee per gas unit that can be paid by the userOperation
maxPriorityFeePerGasbigNumberishyesThe maximum priority fee per gas unit that can be paid by the userOperation

Error Handling

HTTP StatusMeaning
200OK
403Unauthorized userOperation - validation failure
512Internal server error while signing userOperation
515Error during partial userOp parsing. Wrong input format for the partial userOp

Code Examples

Installation

tsx
npm i node-fetch
npm i node-fetch

Request

tsx
data: IUserOperation
const dataWithChainId = {
  ...data,
  chainid: this.chainId,
}


const url = `${this.backendUrl}/sign-paymaster-op`
let config = {
  method: "post",
  maxBodyLength: Infinity,
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${this.apiKey}`,
  },
  body: JSON.stringify(dataWithChainId),
};


const response = await fetch(url, config)
const JSONResponse = await response.json();
data: IUserOperation
const dataWithChainId = {
  ...data,
  chainid: this.chainId,
}


const url = `${this.backendUrl}/sign-paymaster-op`
let config = {
  method: "post",
  maxBodyLength: Infinity,
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${this.apiKey}`,
  },
  body: JSON.stringify(dataWithChainId),
};


const response = await fetch(url, config)
const JSONResponse = await response.json();