webauthnGasEstimator

A middleware function to estimate the gas usage of a user operation when using a Modular Account V2 WebAuthn account. Has an optional custom gas estimator. This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in getImplementationAddress().

Import

1import { webauthnGasEstimator } from "@aa-sdk/core";

Usage

import {
  
import webauthnGasEstimator
webauthnGasEstimator
,
function createSmartAccountClient<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = UserOperationContext | undefined>(config: SmartAccountClientConfig<TTransport, TChain, TAccount, TContext>): SmartAccountClient<TTransport, TChain, TAccount>
createSmartAccountClient
,
type
type SmartAccountClient<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, actions extends Record<string, unknown> = Record<...>, rpcSchema extends RpcSchema = [...], context extends UserOperationContext | undefined = UserOperationContext | undefined> = { [K in keyof Client<transport, chain, account, rpcSchema, actions & { buildUserOperation: (args: BuildUserOperationParameters<account, context>) => Promise<...>; ... 11 more ...; signTypedData: <const TTypedData extends { ...; } | { ...; }, TPrimaryType extends string = string>(args: SignTypedDataParameters<...>) => Promise<Hex>; } & (IsUndefined<...> extends false ? { ...; } : { ...; }) & BundlerActions & PublicActions>]: Client<...>[K]; }
SmartAccountClient
,
} from "@aa-sdk/core"; import {
function createModularAccountV2<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner<any>>(config: CreateModularAccountV2Params<TTransport, TSigner>): Promise<ModularAccountV2<TSigner>>
createModularAccountV2
,
type
type CreateModularAccountV2ClientParams<TTransport extends Transport = Transport, TChain extends Chain = Chain, TSigner extends SmartAccountSigner = SmartAccountSigner<any>> = CreateModularAccountV2Params<TTransport, TSigner> & Omit<{ type?: string | undefined | undefined; cacheTime?: number | undefined | undefined; chain?: Chain | ... 1 more ... | undefined; ... 13 more ...; signUserOperation?: ClientMiddlewareFn<...> | undefined; }, "chain" | ... 1 more ... | "account">
CreateModularAccountV2ClientParams
,
} from "@account-kit/smart-contracts"; const
const credential: { id: string; publicKey: string; }
credential
= {
id: string
id
: "credential-id",
publicKey: string
publicKey
: "0x...",
}; async function
function createWebauthnAccountClient(config: CreateModularAccountV2ClientParams): Promise<SmartAccountClient>
createWebauthnAccountClient
(
config: CreateModularAccountV2ClientParams
config
:
type CreateModularAccountV2ClientParams<TTransport extends Transport = Transport, TChain extends Chain = Chain, TSigner extends SmartAccountSigner = SmartAccountSigner<any>> = CreateModularAccountV2Params<TTransport, TSigner> & Omit<{ type?: string | undefined | undefined; cacheTime?: number | undefined | undefined; chain?: Chain | ... 1 more ... | undefined; ... 13 more ...; signUserOperation?: ClientMiddlewareFn<...> | undefined; }, "chain" | ... 1 more ... | "account">
CreateModularAccountV2ClientParams
,
):
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<
type SmartAccountClient<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, actions extends Record<string, unknown> = Record<...>, rpcSchema extends RpcSchema = [...], context extends UserOperationContext | undefined = UserOperationContext | undefined> = { [K in keyof Client<transport, chain, account, rpcSchema, actions & { buildUserOperation: (args: BuildUserOperationParameters<account, context>) => Promise<...>; ... 11 more ...; signTypedData: <const TTypedData extends { ...; } | { ...; }, TPrimaryType extends string = string>(args: SignTypedDataParameters<...>) => Promise<Hex>; } & (IsUndefined<...> extends false ? { ...; } : { ...; }) & BundlerActions & PublicActions>]: Client<...>[K]; }
SmartAccountClient
> {
const
const webauthnAccount: ModularAccountV2<SmartAccountSigner<any>>
webauthnAccount
= await
createModularAccountV2<Transport, SmartAccountSigner<any>>(config: CreateModularAccountV2Params<Transport, SmartAccountSigner<any>>): Promise<...>
createModularAccountV2
({
...
config: CreateModularAccountV2ClientParams
config
,
mode: "webauthn"
mode
: "webauthn",
credential: { id: string; publicKey: string; }
credential
,
}); return
createSmartAccountClient<Transport, Chain, any, UserOperationContext | undefined>(config: { type?: string | undefined | undefined; cacheTime?: number | undefined | undefined; chain?: Chain | undefined; ... 13 more ...; signUserOperation?: ClientMiddlewareFn<...> | undefined; }): { ...; }
createSmartAccountClient
({
account?: any
account
:
any
webAuthnAccount
,
gasEstimator?: ClientMiddlewareFn<UserOperationContext | undefined> | undefined
gasEstimator
:
import webauthnGasEstimator
webauthnGasEstimator
(
config: CreateModularAccountV2ClientParams
config
.
gasEstimator?: ClientMiddlewareFn<UserOperationContext | undefined> | undefined
gasEstimator
),
...
config: CreateModularAccountV2ClientParams
config
,
}); }

Parameters

gasEstimator

ClientMiddlewareFn Optional custom gas estimator function

Returns

ClientMiddlewareFn A function that takes user operation struct and parameters, estimates gas usage, and returns the user operation with gas limits.