sendTokenPaymasterUserOp
This method combines the preparation and sending of a user operation that uses token paymaster for gas payment. It handles the entire flow of:
- Preparing the user operation with token paymaster configuration
- Adding token approval if needed
- Signing and sending the operation
Usage
example.ts
import { createSmartAccountClient } from "./nexusClient"
const hash = await nexusClient.sendTokenPaymasterUserOp({
calls: [
{
to: recipientAddress,
value: 1n,
data: "0x"
}
],
feeTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC address
})
Parameters
calls
{ to: Address, data: Hex, value: bigint }[]
: Array of transactions to be executedfeeTokenAddress
Address
: The ERC20 token address to be used for paying gas feescustomApprovalAmount
bigint
(optional): Custom approval amount for the token paymastermaxFeePerGas
bigint
(optional): Maximum fee per gas unitmaxPriorityFeePerGas
bigint
(optional): Maximum priority fee per gas unit
Response
Promise<Hash>
: Returns the transaction hash of the submitted user operation
Error Handling
The method will throw an error if:
- The client account is not properly configured
- The paymaster context is missing or invalid
- Token approval fails
- User operation submission fails
Related Methods
- prepareTokenPaymasterUserOp - If you need more control over the preparation step
- sendTransaction - For sending transactions without token paymaster