diff --git a/packages/core/src/account/smartContractAccount.ts b/packages/core/src/account/smartContractAccount.ts index 9729781f6b..e74dbc8f9c 100644 --- a/packages/core/src/account/smartContractAccount.ts +++ b/packages/core/src/account/smartContractAccount.ts @@ -78,7 +78,7 @@ export type SmartContractAccount< typedDataDefinition: TypedDataDefinition ) => Promise; encodeUpgradeToAndCall: (params: UpgradeToAndCallParams) => Promise; - getNonce(): Promise; + getNonce(nonceKey?: bigint): Promise; getInitCode: () => Promise; isAccountDeployed: () => Promise; getFactoryAddress: () => Address; @@ -244,12 +244,12 @@ export async function toSmartContractAccount< return initCode === "0x"; }; - const getNonce = async () => { + const getNonce = async (nonceKey = 0n) => { if (!(await isAccountDeployed())) { return 0n; } - return entryPointContract.read.getNonce([accountAddress_, BigInt(0)]); + return entryPointContract.read.getNonce([accountAddress_, nonceKey]); }; const account = toAccount({ diff --git a/packages/core/src/actions/smartAccount/buildUserOperation.ts b/packages/core/src/actions/smartAccount/buildUserOperation.ts index 524f752916..07121a1753 100644 --- a/packages/core/src/actions/smartAccount/buildUserOperation.ts +++ b/packages/core/src/actions/smartAccount/buildUserOperation.ts @@ -35,7 +35,7 @@ export const buildUserOperation: < uo: { initCode: account.getInitCode(), sender: account.address, - nonce: account.getNonce(), + nonce: account.getNonce(overrides?.nonceKey), callData: Array.isArray(uo) ? account.encodeBatchExecute(uo) : typeof uo === "string" diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 7e0f553383..e9007f59cf 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -54,6 +54,14 @@ export type UserOperationOverrides = Partial<{ | UserOperationStruct["verificationGasLimit"] | Percentage; paymasterAndData: UserOperationStruct["paymasterAndData"]; + /** + * This can be used to override the key used when calling `entryPoint.getNonce` + * It is useful when you want to use parallel nonces for user operations + * + * NOTE: not all bundlers fully support this feature and it could be that your bundler will still only include + * one user operation for your account in a bundle + */ + nonceKey: bigint; }>; // represents the request as it needs to be formatted for RPC requests