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.

For a deeper understanding of how to employ this method to provide varied user experiences contingent on gas sponsorship eligibility, please refer to the guide How to handle User Operations not eligible for gas sponsorship.

Usage

example.ts
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.`
);

Returns

Promise<boolean>

A Promise containing the boolean value indicating whether the UO to be sent is eligible for gas sponsorship or not.

Parameters

SendUserOperationParameters

SendUserOperationParameters
export type SendUserOperationParameters<
  TAccount extends SmartContractAccount | undefined,
  TContext extends UserOperationContext | undefined =
    | UserOperationContext
    | undefined,
  TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>
> = {
  uo: UserOperationCallData | BatchUserOperationCallData;
} & GetAccountParameter<TAccount> &
  GetContextParameter<TContext> &
  UserOperationOverridesParameter<TEntryPointVersion>;
  • uo: UserOperationCallData | BatchUserOperationCallData

    UserOperationCallData
    export type UserOperationCallData =
      | {
          /* the target of the call */
          target: Address;
          /* the data passed to the target */
          data: Hex;
          /* the amount of native token to send to the target (default: 0) */
          value?: bigint;
        }
      | Hex;
    • target: Address - the target of the call (equivalent to to in a transaction)
    • data: Hex - can be either 0x or a call data string
    • value?: bigint - optionally, set the value in wei you want to send to the target
  • overrides?: UserOperationOverrides

Optional parameter where you can specify override values for maxFeePerGas, maxPriorityFeePerGas, callGasLimit, preVerificationGas, verificationGasLimit, paymasterAndData, or nonceKey for the user operation request. You can also specify a stateOverride to be passed into eth_estimateUserOperationGas during gas estimation.

  • account?: TAccount extends SmartContractAccount | undefined

When using this action, if the SmartContractAccount has not been connected to the SmartAccountClient (e.g. SmartAccountClient not instantiated with your SmartContractAccount during createSmartAccountClient). You can check if the account is connected to the client by checking the account field of SmartAccountClient. If the account is not connected, you can specify the SmartContractAccount instance to use for the function call.