> For the complete documentation index, see [llms.txt](https://docs.cometh.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cometh.io/resources/migrate-from-the-connect-legacy-sdk.md).

# Migrate from the connect legacy SDK

{% hint style="info" %}
If you already have a connect license, **please contact us so that we update you to the new 4337 licensing model**.
{% endhint %}

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.&#x20;
* If the user was using a Passkey as signer, the [safeWebAuthnSharedSigner](https://github.com/safe-global/safe-modules/blob/main/modules/passkey/contracts/4337/SafeWebAuthnSharedSigner.sol) will be added as an owner and configured to work with the user's Passkey.

{% hint style="warning" %}
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.
{% endhint %}

This is the flow you are supposed to follow:

```typescript
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
});

```

You can also check if the safe account has been migrated:

```typescript
const isTheAccountMigrated = await legacyClient.hasMigrated()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cometh.io/resources/migrate-from-the-connect-legacy-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
