Migrate an account from the legacy SDK to the 4337 SDK
If you already have a connect license, please contact us so that we update you to the new 4337 licensing model.
The migration will allow you to use Safe 1.3.0 accounts created with Connect Legacy in the Connect 4337 SDK.
What will happen:
The Safe account is migrated to version 1.4.1.
If the user was using a Passkey as signer, the safeWebAuthnSharedSigner will be added as an owner and configured to work with the user's Passkey.
If you have multiple passkeys controlling the account, only the passkey on the device you are doing the migration will be usable. Other passkeys won't be working and should be removed.
This is the flow you are supposed to follow:
import { ENTRYPOINT_ADDRESS_V07, createComethPaymasterClient, createLegacySafeSmartAccount, createSafeSmartAccount, createSmartAccountClient} from"@cometh/connect-sdk-4337";import { http, encodeFunctionData } from"viem;import { gnosis } from"viem/chains";import countContractAbi from"../contract/counterABI.json";constapiKeyLegacy=process.env.NEXT_PUBLIC_COMETH_LEGACY_API_KEY;constapiKey4337=process.env.NEXT_PUBLIC_COMETH_4337_API_KEY;constchain= gnosis;constbundlerUrl="https://bundler.cometh.io/"+CHAIN_ID+"?apikey="+COMETH_4337_API_KEY;constpaymasterUrl="https://paymaster.cometh.io/"+CHAIN_ID+"?apikey="+COMETH_4337_API_KEY;// Step 1 - This is the address of you safe using the connect legacyconstsmartAccountAddress=LEGACY_ADDRESS// Step 2 - Create the legacy ts object to available migration constlegacyClient=awaitcreateLegacySafeSmartAccount({ apiKeyLegacy, apiKey4337, chain, smartAccountAddress})// Step 3 - Migrate the safe awaitlegacyClient.migrate()// Your Safe is now migrated, you can use the 4337 SDK// Create the new ts object to handle the upgraded safeconstupdatedSmartAccount=awaitcreateSafeSmartAccount({ apiKey, chain, smartAccountAddress, entrypoint:ENTRYPOINT_ADDRESS_V07});constpaymasterClient=awaitcreateComethPaymasterClient({ transport:http(paymasterUrl), chain, entrypoint:ENTRYPOINT_ADDRESS_V07});constsmartAccountClient=createSmartAccountClient({ account: updateSmartAccount, entrypoint:ENTRYPOINT_ADDRESS_V07, chain, bundlerTransport :http(bundlerUrl), middleware:{ sponsorUserOperation:paymasterClient.sponsorUserOperation, gasPrice:paymasterClient.gasPrice },});constcalldata=encodeFunctionData({ abi: countContractAbi, functionName:"count});//You can send transaction witht the new sdkconsttxHash=awaitsmartAccountClient.sendTransaction({ to:COUNTER_CONTRACT_ADDRESS, data: calldata});
You can also check if the safe account has been migrated: