Complete guide to migrate your BiconomyV2 smart accounts to the newer Nexus smart accounts
This guide explains how to migrate your BiconomySmartAccountV2 smart accounts to the newer Nexus smart accounts. The migration process preserves your account’s address, balance, and history while upgrading to Nexus’s enhanced architecture.
First, set up the necessary connections to your V2 smart account:
Copy
Ask AI
import { createWalletClient, http } from "viem";import { privateKeyToAccount } from "viem/accounts";import { baseSepolia } from "viem/chains";import { createSmartAccountClient as createV2Client, BiconomySmartAccountV2, PaymasterMode} from "@biconomy/account";import { getMEEVersion, MEEVersion } from "@biconomy/abstractjs";import dotenv from "dotenv";dotenv.config();// Use the version that suits your needs from the list// See MEE Versioningconst version = MEEVersion.V2_1_0;const versionConfig = getMEEVersion(version)// Define configuration variablesconst config = { // Chain and network information chain: baseSepolia, // EOA credentials eoaPrivateKey: process.env.EOA_PRIVATE_KEY, // Replace with your private key eoaAddress: process.env.EOA_ADDRESS, // Replace with your EOA address // Biconomy infrastructure URLs v2BundlerUrl: process.env.V2_BUNDLER_URL, // Replace with your V2 bundler URL nexusBundlerUrl: process.env.NEXUS_BUNDLER_URL, // Replace with your Nexus bundler URL // API keys paymasterApiKey: process.env.PAYMASTER_API_KEY, // Replace with your Paymaster API key // Nexus contract addresses nexusImplementationAddress: versionConfig.implementationAddress, nexusBootstrapAddress: versionConfig.bootStrapAddress,};// Connect to your EOAconst eoaAccount = privateKeyToAccount(config.eoaPrivateKey as `0x${string}`);const client = createWalletClient({ account: eoaAccount, chain: config.chain, transport: http(),});// Connect to your V2 smart accountconst V2Account = await createV2Client({ signer: client, biconomyPaymasterApiKey: config.paymasterApiKey, bundlerUrl: config.v2BundlerUrl!,});// Get V2 account addressconst V2AccountAddress = await V2Account.getAccountAddress();console.log("V2 Account Address:", V2AccountAddress);
Update your application to use the Nexus SDK for all future interactions:
Copy
Ask AI
// IMPORTANT: Always use the same address as your V2 accountconst migratedAccountAddress = "YOUR_V2_ACCOUNT_ADDRESS";// Use this pattern for all future SDK interactions// Use the same version you used to get implementation address to upgrade toconst nexusAccount = await toNexusAccount({ signer: eoaAccount, chainConfiguration: { chain: base, transport: http(), version: getMEEVersion(version) }, accountAddress: migratedAccountAddress});const bundlerClient = createBicoBundlerClient({ account: nexusAccount, transport: http(bundlerUrl)});
After successfully migrating your V2 account to Nexus:
Post-Migration Actions
1
Store Account Address
STORE YOUR ACCOUNT ADDRESS in your application’s persistent storage
2
Update Application Code
Update your application code to use the accountAddress parameter in all future interactions
3
Test Thoroughly
Test thoroughly with real transactions to ensure everything works as expected
By following this migration guide and properly storing your account address, you’ve successfully upgraded your V2 account to a Nexus account while preserving its address, balance, and history.