This import will migrate your safe and make it usable with passkeys in cometh connect.
import {
ENTRYPOINT_ADDRESS_V07,
createComethPaymasterClient,
createSafeSmartAccount,
createSmartAccountClient,
importSafeActions,
} from "@cometh/connect-sdk-4337";
import { http, encodeFunctionData } from "viem;
import { gnosis } from "viem/chains";
import countContractAbi from "../contract/counterABI.json";
import { privateKeyToAccount } from "viem/accounts";
const apiKey = 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 = WALLET_ADDRESS_TO_IMPORT
// Your current owner
const signer = privateKeyToAccount(PK)
const safe4337SmartAccount = await createSafeSmartAccount({
apiKey,
chain: gnosis,
smartAccountAddress: legacyWalletAddress,
entryPoint: ENTRYPOINT_ADDRESS_V07,
signer,
});
const paymasterClient = await createComethPaymasterClient({
transport: http(paymasterUrl),
chain: gnosis,
entryPoint: ENTRYPOINT_ADDRESS_V07,
});
const smartAccountClient = createSmartAccountClient({
account: safe4337SmartAccount,
entryPoint: ENTRYPOINT_ADDRESS_V07,
chain: gnosis,
bundlerTransport: http(bundlerUrl),
middleware: {
sponsorUserOperation: paymasterClient.sponsorUserOperation,
gasPrice: paymasterClient.gasPrice,
},
});
const extendedClient = smartAccountClient.extend(importSafeActions());
const importMessage = await extendedClient.prepareImportSafe1_3Tx();
const signature = (await extendedClient.signTransactionByExternalOwner({
signer,
tx: importMessage.tx,
})) as Hex;
await extendedClient.importSafe({
signature,
...importMessage
});
//previous code is the same as 1.3.0
const importMessage = await extendedClient.prepareImportSafe1_4Tx();
// after code is the same as 1.3.0
import {
ENTRYPOINT_ADDRESS_V07,
createComethPaymasterClient,
createSafeSmartAccount,
createSmartAccountClient,
} from "@cometh/connect-sdk-4337";
import { http, encodeFunctionData } from "viem;
import { gnosis } from "viem/chains";
import countContractAbi from "../contract/counterABI.json";
const smartAccountAddress = WALLET_ADDRESS_IMPORTED
const importedAccount = await createSafeSmartAccount({
apiKey,
chain: gnosis,
smartAccountAddress: ,
entryPoint: ENTRYPOINT_ADDRESS_V07,
});
const smartAccountClient = createSmartAccountClient({
account: importedAccount,
entrypoint: ENTRYPOINT_ADDRESS_V07,
chain,
bundlerTransport : http(bundlerUrl),
middleware:{
sponsorUserOperation: paymasterClient.sponsorUserOperation,
gasPrice: paymasterClient.gasPrice
},
});
const calldata = encodeFunctionData({
abi: countContractAbi,
functionName: "count
});
//You can send transaction
const txHash = await smartAccountClient.sendTransaction({
to: COUNTER_CONTRACT_ADDRESS,
data: calldata
});