Class BaseAccountAPI

Base class for all Smart Wallet ERC-4337 Clients to implement. Subclass should inherit 5 methods to support a specific wallet contract:

  • getAccountInitCode - return the value to put into the "initCode" field, if the account is not yet deployed. should create the account instance using a factory contract.
  • getNonce - return current account's nonce value
  • encodeExecute - encode the call from entryPoint through our account to the target contract.
  • signUserOpHash - sign the hash of a UserOp.

The user can use the following APIs:

  • createUnsignedUserOp - given "target" and "calldata", fill userOp to perform that operation from the account.
  • createSignedUserOp - helper to call the above createUnsignedUserOp, and then extract the userOpHash and sign it

Hierarchy

Index

Constructors

constructor

  • base constructor. subclass SHOULD add parameters that define the owner (signer) of this wallet

    Parameters

    Returns BaseAccountAPI

Properties

Optional accountAddress

accountAddress: string

context

context: Context

entryPointAddress

entryPointAddress: string

factoryUsed

factoryUsed: Factory

Optional overheads

overheads: Partial<GasOverheads>

Optional paymasterAPI

paymasterAPI: PaymasterAPI

provider

provider: Provider

Readonly services

services: Context["services"]

Accessors

error$

  • get error$(): ErrorSubject
  • Returns ErrorSubject

state

state$

  • get state$(): BehaviorSubject<State>
  • Returns BehaviorSubject<State>

supportedNetworks

  • get supportedNetworks(): Network[]

Methods

checkAccountPhantom

  • checkAccountPhantom(): Promise<boolean>
  • check if the contract is already deployed.

    Returns Promise<boolean>

createSignedUserOp

createUnsignedUserOp

  • create a UserOperation, filling all details (except signature)

    • if account is not yet created, add initCode to deploy it.
    • if gas or nonce are missing, read them from the chain (note that we can't fill gaslimit before the account is created)

    Parameters

    Returns Promise<UserOperationStruct>

destroy

  • destroy(): void
  • destroys

    Returns void

encodeUserOpCallDataAndGasLimit

  • encodeUserOpCallDataAndGasLimit(detailsForUserOp: TransactionDetailsForUserOp): Promise<{ callData: string; callGasLimit: BigNumber }>

estimateCreationGas

  • estimateCreationGas(initCode?: string): Promise<BigNumberish>
  • Parameters

    • Optional initCode: string

    Returns Promise<BigNumberish>

getAccountAddress

  • getAccountAddress(): Promise<string>
  • return the account's address. this value is valid even before deploying the contract.

    Returns Promise<string>

getCounterFactualAddress

  • getCounterFactualAddress(): Promise<string>
  • calculate the account address even before it is deployed

    Returns Promise<string>

getInitCode

  • getInitCode(): Promise<string>
  • return initCode value to into the UserOp. (either deployment code, or empty hex if contract already deployed)

    Returns Promise<string>

getNetworkChainId

  • Parameters

    Returns number

getPreVerificationGas

  • should cover cost of putting calldata on-chain, and some overhead. actual overhead depends on the expected bundle size

    Parameters

    Returns Promise<number>

getUserOpHash

  • return userOpHash for signing. This value matches entryPoint.getUserOpHash (calculated off-chain, to avoid a view call)

    Parameters

    Returns Promise<string>

getUserOpReceipt

  • getUserOpReceipt(userOpHash: string, timeout?: number, interval?: number): Promise<string | null>
  • get the transaction that has this userOpHash mined, or null if not found

    Parameters

    • userOpHash: string

      returned by sendUserOpToBundler (or by getUserOpHash..)

    • Default value timeout: number = 30000

      stop waiting after this timeout

    • Default value interval: number = 5000

      time to wait between polls.

    Returns Promise<string | null>

    the transactionHash this userOp was mined, or null if not found.

getVerificationGasLimit

  • getVerificationGasLimit(): Promise<BigNumberish>
  • return maximum gas used for verification. NOTE: createUnsignedUserOp will add to this value the cost of creation, if the contract is not yet created.

    Returns Promise<BigNumberish>

init

  • init(): Promise<this>
  • Returns Promise<this>

packUserOp

require

  • require(options?: { network?: boolean; wallet?: boolean }): Promise<void>
  • Parameters

    • Default value options: { network?: boolean; wallet?: boolean } = {}
      • Optional network?: boolean
      • Optional wallet?: boolean

    Returns Promise<void>

setPaymasterApi

  • setPaymasterApi(paymaster: PaymasterAPI | null): Promise<void>
  • Parameters

    Returns Promise<void>

signMessage

  • signs message

    Parameters

    Returns Promise<string>

    Promise

signTypedData

  • signTypedData(types: TypedDataField[], message: any): Promise<string>
  • Parameters

    • types: TypedDataField[]
    • message: any

    Returns Promise<string>

signUserOp

validateResolveName

  • validateResolveName(options?: { name?: string; network?: number }): Promise<void>
  • Parameters

    • Default value options: { name?: string; network?: number } = {}
      • Optional name?: string
      • Optional network?: number

    Returns Promise<void>