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

Commit 7accc82

Browse files
authored
Fix: prevent AA20 when deploying new SimpleAccount with nonceKey > 0 (#113)
1 parent d2a1785 commit 7accc82

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/preset/builder/simpleAccount.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ export class SimpleAccount extends UserOperationBuilder {
5353
}
5454

5555
private resolveAccount: UserOperationMiddlewareFn = async (ctx) => {
56-
ctx.op.nonce = await this.entryPoint.getNonce(ctx.op.sender, this.nonceKey);
57-
ctx.op.initCode = ctx.op.nonce.eq(0) ? this.initCode : "0x";
56+
const [nonce, code] = await Promise.all([
57+
this.entryPoint.getNonce(ctx.op.sender, this.nonceKey),
58+
this.provider.getCode(ctx.op.sender),
59+
]);
60+
ctx.op.nonce = nonce;
61+
ctx.op.initCode = code === "0x" ? this.initCode : "0x";
5862
};
5963

6064
public static async init(

0 commit comments

Comments
 (0)