Migrate a dapp to a different network
To migrate a dApp from one network to another network within the Terp Network ecosystem, you would essentially have to:
- Make sure your dapp is compatible with the new network. You can get details on any breaking changes in the chain upgrades history.
- Potentially modify the smart contract code. For example to take into account any breaking changes, or updating smart contracts' addresses.
- Update your tooling.
- Store and instantiate the smart contract on the new network.
- Migrate the smart contract state.
Compatibility check and adjustments
Code changes might be required when migrating your dApp to a new Terp Network network due to different factors. You can get details on any change that could have affected your dapp in the chain upgrades history.
Some examples of changes that may have affected your dapp are:
- Network-Specific Parameters: The new network might have different configurations or parameters compared to the old one. This can include changes in block time, transaction costs, gas limits, or staking parameters.
- Smart Contract Interactions: If your smart contracts interact with other contracts already deployed on the network, those contracts' addresses might change in the new network, necessitating adjustments in your contracts' code. Protocol or API Changes: The new network may have updated versions of the Cosmos SDK or CosmWasm, with changes or enhancements to the APIs, data structures, or protocol behavior that might require modifications in your contracts or dApp code.
If you noticed any breaking changes, you should make sure to update the smart contracts code accordingly.
Updating the smart contracts
If your smart contract needs to interact with other smart contracts, you need to make sure to specify the correct smart contracts addresses. As the network changes, so do the addresses of every smart contracts (as it needs to be redeployed)
You may need to make adjustments in the smart contracts' code to interact with new contract addresses.
Update the tool you are using to the correct version
First, ensure that the tool you are using is updated to the latest version. This will ensure you have the latest functionalities, including any necessary features for migration.
Re-deploy your dapp to the new network
Make sure to check our guides for step-by-step instructions. Depending on if you needed to perform any changes to your smart contract code, you may need to re-build the project.
Migrate smart contracts' state
State migration refers to transferring the state (data) of the smart contracts from the old network to the new one. You could perform a state migration through a script that reads the state from the old contracts and then calls appropriate methods on the new contracts to replicate the state.
The state migration process consists in three main steps:
State Extraction: First, extract the state from the existing contracts on the network you are migrating from. This process will depend on the design of your smart contracts. You may need to call certain query methods to retrieve all the necessary state data.
State Transformation: Depending on the differences between the old and new networks or changes in your contract, you might need to transform the state data. This step includes processes like data conversion, mapping to new data structures, or applying specific data manipulation rules.
State Injection: After the state data has been correctly prepared, the next step is to inject it into the new contracts on the new network. This process involves calling specific methods on your new contracts that accept state data and store it. These methods should be designed to correctly populate the contract's state from the incoming data.