Uninstalling Modules from Axir Smart Account
This guide explains how to safely uninstall modules from your Axir smart account.
Prerequisites
First, import the required dependencies:
import { AxirCore } from "axr-erc4337-sdk";
import { ethers } from "ethers";
import { type Hex } from "viem";
Implementation
1. Initialize AxirCore
First, create an instance of AxirCore:
const axirCore = new AxirCore(
process.env.PRIVATE_KEY as Hex,
process.env.RPC_URL as string,
process.env.BUNDLER_URL as string,
BigInt(0), // nonce
"baseSepolia" // network name
);
2. Uninstall Module
// Prepare module uninstallation UserOperation
const moduleUninstallOp = await axirCore.generateUnInstallModuleUserOperation(
moduleAddress,
moduleType,
"0x", // Usually empty for uninstallation
undefined,
usePaymaster,
paymasterType
);
// Estimate gas costs
const uninstallGasEstimate = await axirCore.estimateUserOperationGas(
moduleUninstallOp,
usePaymaster,
paymasterType
);
console.log("Gas Estimation for module uninstallation:");
if (uninstallGasEstimate.totalGasFeeInEth) {
console.log(
`Estimated gas fee in ETH: ${ethers.formatEther(
uninstallGasEstimate.totalGasFeeInEth
)} ETH`
);
}
// Execute the uninstallation
const txHash = await axirCore.executeUserOperation(moduleUninstallOp);
console.log("Module uninstallation hash:", txHash);
// Verify uninstallation
const isStillInstalled = await axirCore.isModuleInstalled(
moduleAddress,
moduleType,
"0x"
);
console.log("Is module still installed?", isStillInstalled);
warning
Before uninstalling a module:
- Ensure you have alternative recovery/validation methods in place
- Verify that no ongoing operations depend on the module
- Double-check the module address and type
tip
It's recommended to verify the uninstallation was successful using isModuleInstalled before proceeding with any other operations.