Skip to content

Sponsor User Operation

You can interact with Kriptonio Paymaster either via SDK or REST API.

SDK

To sponsor a user operation, you first need to get the paymaster endpoint URL. You can get it from the Kriptonio web interface or via the create or getOrCreate paymaster SDK methods.

After that, you call the sponsorUserOperation function and provide user operation data to obtain a paymasterAndData value that you will attach to your user operation before sending it.

When the user operation is sent, the entry-point will read paymasterAndData and use it to pull the gas fee from Kriptonio Paymaster instead of from the user's wallet.

The function also returns gas values that you need to set to your user operation before submitting it.

import { ChainId, KriptonioSdk, sponsorUserOperation } from '@kriptonio/sdk';
 
const sdk = new KriptonioSdk({
  accessToken: 'your-access-token',
});
 
const entryPoint = '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789';
 
const paymaster = await sdk.paymaster.getOrCreate({
  entryPoint,
  wallet: '0x123',
  chainId: ChainId.Polygon,
});
 

const data = await sponsorUserOperation(
  paymaster.url,
  {
    callData: '0x123',
    initCode: '0x',
    nonce: 0n,
    paymasterAndData: '0x',
    sender: '0x123',
    signature: '0x',
    callGasLimit: 0n,
    preVerificationGas: 0n,
    verificationGasLimit: 0n,
    maxFeePerGas: 0n,
    maxPriorityFeePerGas: 0n,
  },
  entryPoint,
);
 
console.log('paymaster and data', data.paymasterAndData);

REST API

URL:

https://paymaster.kriptonio.com/v1/endpoints/<your-access-token>/sponsor

Method:

POST

JSON Body:

{
  "userOperation": {
    "sender": "string",
    "nonce": "string",
    "initCode": "string",
    "callData": "string",
    "callGasLimit": "string",
    "verificationGasLimit": "string",
    "preVerificationGas": "string",
    "maxFeePerGas": "string",
    "maxPriorityFeePerGas": "string",
    "paymasterAndData": "string",
    "signature": "string"
  },
  "entryPoint": "string"
}

Returns:

{
  "paymasterAndData": "string",
  "preVerificationGas": "string",
  "verificationGasLimit": "string",
  "callGasLimit": "string"
}