UNPKG

@alchemy/aa-core

Version:

viem based SDK that enables interactions with ERC-4337 Smart Accounts. ABIs are based off the definitions generated in @account-abstraction/contracts

34 lines 1.37 kB
import { isBaseSmartAccountClient } from "../../client/isSmartAccountClient.js"; import { AccountNotFoundError } from "../../errors/account.js"; import { IncompatibleClientError } from "../../errors/client.js"; import { sendUserOperation } from "./sendUserOperation.js"; import { waitForUserOperationTransaction } from "./waitForUserOperationTransacation.js"; export const upgradeAccount = async (client, args) => { const { account = client.account, upgradeTo, overrides, waitForTx, context, } = args; if (!account) { throw new AccountNotFoundError(); } if (!isBaseSmartAccountClient(client)) { throw new IncompatibleClientError("BaseSmartAccountClient", "upgradeAccount", client); } const { implAddress: accountImplAddress, initializationData } = upgradeTo; const encodeUpgradeData = await account.encodeUpgradeToAndCall({ upgradeToAddress: accountImplAddress, upgradeToInitData: initializationData, }); const result = await sendUserOperation(client, { uo: { target: account.address, data: encodeUpgradeData, }, account, overrides, context, }); let hash = result.hash; if (waitForTx) { hash = await waitForUserOperationTransaction(client, result); } return hash; }; //# sourceMappingURL=upgradeAccount.js.map