canSponsorUserOperation
Checks if a user operation can be sponsored by the configured paymaster. Works for both single transactions and batch transactions. This is useful to determine if the user will need to pay gas fees or if the operation qualifies for gas sponsorship.Usage
Parameters
You must provide either awalletAccount or a kernelClient, but not both.
Returns
Promise<boolean> - Returns true if the user operation can be sponsored, false otherwise.
Examples
Single transaction with wallet account
Batch transaction
Using existing kernel client
Error handling
React
UsecanSponsorUserOperation inside a button handler to conditionally show a “gasless” badge or adjust UI before sending:
Related functions
- sendUserOperation - Send a user operation (single or batch)
- estimateUserOperationGas - Estimate gas for a user operation
- createKernelClientForWalletAccount - Create a ZeroDev Kernel client
- isGasSponsorshipError - Check if an error is a gas sponsorship error
- Migration guide (v0.9) - Upgrading from the previous transaction API