Skip to content

checkGasSponsorshipEligibility

This function verifies the eligibility of the connected account for gas sponsorship concerning the upcoming UserOperation (UO) that is intended to be sent. Internally, this method invokes buildUserOperation, which navigates through the middleware pipeline, including the PaymasterMiddleware. Its purpose is to construct the UO struct meant for transmission to the bundler. Following the construction of the UO struct, this function verifies if the resulting structure contains a non-empty paymasterAndData field. You can utilize this method before sending the user operation to confirm its eligibility for gas sponsorship. Depending on the outcome, it allows you to tailor the user experience accordingly, based on eligibility.

Import

import { checkGasSponsorshipEligibility } from "@aa-sdk/core";

Usage

import { smartAccountClient } from "./smartAccountClient";

const eligible = await smartAccountClient.checkGasSponsorshipEligibility({
  uo: {
    data: "0xCalldata",
    target: "0xTarget",
    value: 0n,
  },
});
 
console.log(
  `User Operation is ${
    eligible ? "eligible" : "ineligible"
  } for gas sponsorship.`
);

Parameters

client

Client<TTransport, TChain, TAccount> the smart account client to use for making RPC calls

args

SendUserOperationParameters containing the user operation, account, context, and overrides

Returns

Promise<boolean> a Promise containing a boolean indicating if the account is elgibile for sponsorship