mirror of
https://github.com/getwax/wax.git
synced 2026-01-09 15:18:02 -05:00
37 lines
860 B
TypeScript
37 lines
860 B
TypeScript
import { UserOperation } from "./userOpUtils";
|
|
import { ethers } from "ethers";
|
|
import sleep from "./sleep";
|
|
|
|
export default async function sendUserOpAndWait(
|
|
userOp: UserOperation,
|
|
entryPoint: string,
|
|
bundlerProvider: ethers.JsonRpcProvider,
|
|
pollingDelay = 100,
|
|
maxAttempts = 200,
|
|
) {
|
|
const userOpHash = (await bundlerProvider.send("eth_sendUserOperation", [
|
|
userOp,
|
|
entryPoint,
|
|
])) as string;
|
|
|
|
let receipt: { success: boolean } | null = null;
|
|
|
|
let attempts = 0;
|
|
|
|
while (attempts < maxAttempts && receipt === null) {
|
|
await sleep(pollingDelay);
|
|
|
|
receipt = (await bundlerProvider.send("eth_getUserOperationReceipt", [
|
|
userOpHash,
|
|
])) as { success: boolean } | null;
|
|
|
|
attempts++;
|
|
}
|
|
|
|
if (receipt === null) {
|
|
throw new Error(`Could not get receipt after ${maxAttempts} attempts`);
|
|
}
|
|
|
|
return receipt;
|
|
}
|