dropAndReplaceUserOperation
Attempts to drop and replace an existing user operation by increasing fees. The fee replacement logic sets the maxPriorityFee
and maxPriorityFeePerGas
to the max(current_estimate, prev_uo * 1.1)
(i.e. the current max fee or 110% of the previous fee).
Usage
import { smartAccountClient } from "./smartAccountClient";
const { request } = await smartAccountClient.sendUserOperation({
uo: {
data: "0xCalldata",
target: "0xTarget",
value: 0n,
},
});
const { hash: replacedHash } =
await smartAccountClient.dropAndReplaceUserOperation(request);
import { createMultiOwnerModularAccount } from "@alchemy/aa-accounts";
import {
LocalAccountSigner,
SmartAccountSigner,
createSmartAccountClient,
polygonMumbai,
} from "@alchemy/aa-core";
import { http } from "viem";
const chain = polygonMumbai;
const signer: SmartAccountSigner = LocalAccountSigner.mnemonicToAccountSigner(
"YOUR_OWNER_MNEMONIC"
);
const rpcTransport = http("https://polygon-mumbai.g.alchemy.com/v2/demo");
export const smartAccountClient = createSmartAccountClient({
transport: rpcTransport,
chain,
account: await createMultiOwnerModularAccount({
transport: rpcTransport,
chain,
signer,
}),
});
Returns
Promise<{ hash: Hash, request: UserOperationRequest }>
A Promise
containing the hash of the user operation request sent to the bundler with higher gas to be mined faster as the replacement of the input user operation request.
Note: The hash is not the User Operation Receipt. The user operation still needs to be bundled and included in a block. The user operation result is more of a proof of submission than a receipt.
Parameters
DropAndReplaceUserOperationParameters<TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined>
uoToDrop: UserOperationRequest
A previously submitted UserOperationRequest
to be dropped and replaced by a new user operation with higher gas to be mined faster
overrides?:
UserOperationOverrides
Optional parameter where you can specify override values for maxFeePerGas
, maxPriorityFeePerGas
, callGasLimit
, preVerificationGas
, verificationGasLimit
, paymasterAndData
, or nonceKey
for the user operation request
account?: TAccount extends SmartContractAccount | undefined
When using this action, if the SmartContractAccount
has not been connected to the SmartAccountClient
(e.g. SmartAccountClient
not instantiated with your SmartContractAccount
during createSmartAccountClient
). You can check if the account is connected to the client by checking the account
field of SmartAccountClient
. If the account is not connected, you can specify the SmartContractAccount
instance to use for the function call.