# Contract Migration

### Secret Network Client Setup

```javascript
import { SecretNetworkClient, Wallet } from "secretjs";

const wallet = new Wallet("Your mnemonic words go here");

const secretjs = new SecretNetworkClient({
  chainId: "pulsar-3",
  url: "https://pulsar.lcd.secretnodes.com",
  wallet: wallet,
  walletAddress: wallet.address,
});
```

### SecretJS Contract Migration

[**`secretjs.tx.compute.migrateContract()`**](https://secretjs.scrt.network/#secretjstxcomputemigratecontract)

Migrate a contract's code while keeping the same address. Invokes the `migrate()` function on the new code.

Input: [MsgMigrateContractParams](https://secretjs.scrt.network/interfaces/MsgMigrateContractParams)

```ts
const tx = await secretjs.tx.compute.migrateContract(
  {
    sender: myAddress,
    contract_address: contractAddress,
    code_id: newCodeId,
    code_hash: codeHash, // optional but way faster
    msg: {
      migrate_state_to_new_format: {},
    },
    sent_funds: [], // optional
  },
  {
    gasLimit: 100_000,
  },
);
```

{% hint style="info" %}
See [here](https://docs.scrt.network/secret-network-documentation/development/development-concepts/contract-migration/native-from-v1.11) for further docs on contract migration.&#x20;
{% endhint %}


---

# Agent Instructions: 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:

```
GET https://docs.scrt.network/secret-network-documentation/development/frontend/templates/usage-examples/contract-migration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
