Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 6ea20a7

Browse files
authored
Add dryRun to send opts (#21)
1 parent b8d4a96 commit 6ea20a7

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
A simple JS library for building ERC-4337 UserOperations.
66

7+
> **🚀 Looking for access to hosted infrastructure to build your Smart Accounts? Check out [stackup.sh](https://www.stackup.sh/)!**
8+
79
# Usage
810

911
See the `userop` documentation at [docs.stackup.sh](https://docs.stackup.sh/docs/useropjs).

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "userop",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "A simple JS library for building ERC-4337 UserOperations.",
55
"types": "./dist/index.d.ts",
66
"main": "./dist/index.js",

src/client.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "./types";
77
import { EntryPoint, EntryPoint__factory } from "./typechain";
88
import { OpToJSON } from "./utils";
9+
import { UserOperationMiddlewareCtx } from "./context";
910

1011
export class Client implements IClient {
1112
private provider: ethers.providers.JsonRpcProvider;
@@ -41,18 +42,29 @@ export class Client implements IClient {
4142
builder: IUserOperationBuilder,
4243
opts?: ISendUserOperationOpts
4344
) {
45+
const dryRun = Boolean(opts?.dryRun);
4446
const op = await this.buildUserOperation(builder);
4547
opts?.onBuild?.(op);
4648

47-
const userOpHash = (await this.provider.send("eth_sendUserOperation", [
48-
OpToJSON(op),
49-
this.entryPoint.address,
50-
])) as string;
49+
const userOpHash = dryRun
50+
? new UserOperationMiddlewareCtx(
51+
op,
52+
this.entryPoint.address,
53+
this.chainId
54+
).getUserOpHash()
55+
: ((await this.provider.send("eth_sendUserOperation", [
56+
OpToJSON(op),
57+
this.entryPoint.address,
58+
])) as string);
5159
builder.resetOp();
5260

5361
return {
5462
userOpHash,
5563
wait: async () => {
64+
if (dryRun) {
65+
return null;
66+
}
67+
5668
const end = Date.now() + this.waitTimeoutMs;
5769
const block = await this.provider.getBlock("latest");
5870
while (Date.now() < end) {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export interface IClient {
8989
}
9090

9191
export interface ISendUserOperationOpts {
92+
dryRun?: boolean;
9293
onBuild?: (op: IUserOperation) => Promise<any> | any;
9394
}
9495

0 commit comments

Comments
 (0)