alchemyUserOperationSimulator
alchemyUserOperationSimulator
is a middleware method you can use to easily leverage the alchemy_simulateUserOperationAssetChanges
API to simulate asset changes resulting from user operation. Having this as part of your middleware stack will ensure UserOperations
that fail simulation do not get sent unnecessarily.
Usage
ts
import {
alchemyUserOperationSimulator,
createAlchemyRpcClient,
} from "@alchemy/aa-alchemy";
import { createSmartAccountClient } from "@alchemy/aa-core";
import { http } from "viem";
import { sepolia } from "viem/chains";
const alchemyClient = createAlchemyRpcClient({
transport: http("ALCHEMY_RPC_URL"),
chain: sepolia,
});
// use Alchemy to simulate User Ops
const clientWithUserOpSimulator = createSmartAccountClient({
...config,
userOperationSimulator: alchemyUserOperationSimulator(alchemyClient),
});
Returns
ClientMiddlewareFn
A ClientMiddlewareFn
that will simulate a user operation using the Alchemy UserOperation Simulation API.