Migrate from the connect legacy SDK
Migrate an account from the legacy SDK to the 4337 SDK
import {
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";
const apiKeyLegacy = process.env.NEXT_PUBLIC_COMETH_LEGACY_API_KEY;
const apiKey4337 = process.env.NEXT_PUBLIC_COMETH_4337_API_KEY;
const chain = gnosis;
const bundlerUrl = "https://bundler.cometh.io/"+CHAIN_ID+"?apikey="+COMETH_4337_API_KEY;
const paymasterUrl = "https://paymaster.cometh.io/"+CHAIN_ID+"?apikey="+COMETH_4337_API_KEY;
// Step 1 - This is the address of you safe using the connect legacy
const smartAccountAddress = LEGACY_ADDRESS
// Step 2 - Create the legacy ts object to available migration
const legacyClient = await createLegacySafeSmartAccount({
apiKeyLegacy,
apiKey4337,
chain,
smartAccountAddress
})
// Step 3 - Migrate the safe
await legacyClient.migrate()
// Your Safe is now migrated, you can use the 4337 SDK
// Create the new ts object to handle the upgraded safe
const updatedSmartAccount = await createSafeSmartAccount({
apiKey,
chain,
smartAccountAddress,
});
const paymasterClient = await createComethPaymasterClient({
transport: http(paymasterUrl),
chain,
});
const smartAccountClient = createSmartAccountClient({
account: smartAccount,
chain,
paymaster: paymasterClient,
bundlerTransport: http(bundlerUrl),
userOperation: {
estimateFeesPerGas: async () => {
return await paymasterClient.getUserOperationGasPrice();
},
},
})
const calldata = encodeFunctionData({
abi: countContractAbi,
functionName: "count
});
//You can send transaction witht the new sdk
const txHash = await smartAccountClient.sendTransaction({
to: COUNTER_CONTRACT_ADDRESS,
data: calldata
});
Last updated