This repository was archived by the owner on Oct 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +20
-5
lines changed Expand file tree Collapse file tree 4 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 4
4
5
5
A simple JS library for building ERC-4337 UserOperations.
6
6
7
+ > ** 🚀 Looking for access to hosted infrastructure to build your Smart Accounts? Check out [ stackup.sh] ( https://www.stackup.sh/ ) !**
8
+
7
9
# Usage
8
10
9
11
See the ` userop ` documentation at [ docs.stackup.sh] ( https://docs.stackup.sh/docs/useropjs ) .
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " userop" ,
3
- "version" : " 0.1.5 " ,
3
+ "version" : " 0.1.6 " ,
4
4
"description" : " A simple JS library for building ERC-4337 UserOperations." ,
5
5
"types" : " ./dist/index.d.ts" ,
6
6
"main" : " ./dist/index.js" ,
Original file line number Diff line number Diff line change 6
6
} from "./types" ;
7
7
import { EntryPoint , EntryPoint__factory } from "./typechain" ;
8
8
import { OpToJSON } from "./utils" ;
9
+ import { UserOperationMiddlewareCtx } from "./context" ;
9
10
10
11
export class Client implements IClient {
11
12
private provider : ethers . providers . JsonRpcProvider ;
@@ -41,18 +42,29 @@ export class Client implements IClient {
41
42
builder : IUserOperationBuilder ,
42
43
opts ?: ISendUserOperationOpts
43
44
) {
45
+ const dryRun = Boolean ( opts ?. dryRun ) ;
44
46
const op = await this . buildUserOperation ( builder ) ;
45
47
opts ?. onBuild ?.( op ) ;
46
48
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 ) ;
51
59
builder . resetOp ( ) ;
52
60
53
61
return {
54
62
userOpHash,
55
63
wait : async ( ) => {
64
+ if ( dryRun ) {
65
+ return null ;
66
+ }
67
+
56
68
const end = Date . now ( ) + this . waitTimeoutMs ;
57
69
const block = await this . provider . getBlock ( "latest" ) ;
58
70
while ( Date . now ( ) < end ) {
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ export interface IClient {
89
89
}
90
90
91
91
export interface ISendUserOperationOpts {
92
+ dryRun ?: boolean ;
92
93
onBuild ?: ( op : IUserOperation ) => Promise < any > | any ;
93
94
}
94
95
You can’t perform that action at this time.
0 commit comments