simulateUserOperation
simulateUserOperation
is a method you can use to easily leverage the alchemy_simulateUserOperationAssetChanges
API to simulate asset changes resulting from user operation.
Usage
ts
import { smartAccountClient } from "./base-client.ts";
const uoStruct: UserOperationCallData = {
target: "0xTARGET_ADDRESS",
data: "0xDATA",
value: 1n,
};
const uoSimResult = await smartAccountClient.simulateUserOperationAssetChanges({
uo: uoStruct,
});
if (uoSimResult.error) {
console.error(uoSimResult.error.message);
}
const uo = await smartAccountClient.sendUserOperation({ uo: uoStruct });
ts
import { createModularAccountAlchemyClient } from "@alchemy/aa-alchemy";
import { LocalAccountSigner, sepolia } from "@alchemy/aa-core";
export const chain = sepolia;
export const smartAccountClient = await createModularAccountAlchemyClient({
apiKey: "YOUR_API_KEY",
chain,
// you can swap this out for any SmartAccountSigner
signer: LocalAccountSigner.mnemonicToAccountSigner("OWNER_MNEMONIC"),
});
Returns
Promise<SimulateUserOperationAssetChangesResponse>
changes: SimulateAssetChange[]
assetType: SimulateAssetType (NATIVE, ERC20, ERC721, ERC1155, orSPECIAL_NFT)
changeType: SimulateChangeType (APPROVE or TRANSFER)
from: Address
to: Address
rawAmount?: string
amount?: string
contactAddress: Address
tokenId?: string
decimals: number
symbol: string
name?: string
logo?: string
error: SimulateAssetChangesError
message: string
Parameters
UserOperationCallData | UserOperationCallData[]
target: Address
- the target of the call (equivalent toto
in a transaction)data: Hex
- can be either0x
or a call data stringvalue?: 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
or paymasterAndData
on the user operation request. You can also specify a stateOverride
to be passed into eth_estimateUserOperationGas
during gas estimation.