Optional: An Alchemy Gas Policy ID for gasless transactions
Already set up authentication with Para. See our
for details.
For gasless transactions, you’ll need to set up a Gas Manager Policy in your Alchemy Dashboard. This allows you to
sponsor gas fees for your users’ transactions.
UserOperations represent transaction intentions that will be executed by your smart account. Here’s an example of
creating and executing a batch of UserOperations:
Copy
Ask AI
import { encodeFunctionData } from "viem";import { BatchUserOperationCallData, SendUserOperationResult } from "@alchemy/aa-core";// Example contract ABIconst exampleAbi = [ { inputs: [{ internalType: "uint256", name: "_x", type: "uint256" }], name: "changeX", outputs: [], stateMutability: "nonpayable", type: "function", },];// Create batch operationsconst demoUserOperations: BatchUserOperationCallData = [1, 2, 3, 4, 5].map((x) => ({ target: EXAMPLE_CONTRACT_ADDRESS, data: encodeFunctionData({ abi: exampleAbi, functionName: "changeX", args: [x], }),}));// Execute the operationsconst userOperationResult: SendUserOperationResult = await alchemyClient.sendUserOperation({ uo: demoUserOperations,});// Optional: Wait for the operation to be included in a blockconst txHash = await alchemyClient.waitForUserOperationTransaction({ hash: userOperationResult.hash,});
UserOperations are bundled together and executed in a single transaction, making them more gas-efficient than
executing multiple separate transactions.