Skip to content

upgradeAccount

Upgrades smart accounts to a new implementation if the smart contract account supports upgradeability using UUPSUpgradeable Pattern.

Usage

example.ts
import { smartAccountClient as lightAccountClient } from "./lightAccountClient";
import { getMSCAUpgradeToData } from "@alchemy/aa-accounts";
 
const { createMAAccount, ...upgradeToData } = await getMSCAUpgradeToData(
  lightAccountClient,
  { account: lightAccountClient.account }
);
 

const hash = await lightAccountClient.upgradeAccount({
  upgradeTo: upgradeToData,
  waitForTx: true,
});
 
const upgradedAccount = await createMAAccount();

Returns

Promise<Hash>

A Promise that resolves to the user operation hash (transaction hash if waitForTx is true) sent to the network

Parameters

client: SmartContractClient

The SmartContractClient instance

args: UpgradeAccountParams

  • upgradeTo: UpgradeToData

    • implAddress: Address

    Address of new implementation contract address to upgrade to

    • initializationData: Hex

    Encoded contract initiation data for the new implementation contract

  • overrides?: UserOperationOverrides

Optional parameter where you can specify override values for maxFeePerGas, maxPriorityFeePerGas, callGasLimit, preVerificationGas, verificationGasLimit, paymasterAndData, or nonceKey for the user operation request. You can also specify a stateOverride to be passed into eth_estimateUserOperationGas during gas estimation.

  • waitForTx?: boolean

If true, the method would wait for the user operation transaction to be mined