How can I deploy a Sway contract using a salt?

You can now pass a --salt flag in your forc deploy command to redeploy a contract that has been deployed already. This is useful when multiple deployments of the same contract.

In order to use the --salt flag, install the latest forc update by running the following command in your project directory:
cargo add forc

Alternately, you can add the following to your cargo.toml file:
forc = 0.35.2 (pls note that this will have to be updated for the future version updates)

You can now add a --salt to your contractID while deploying the contract as follows:
forc deploy --salt <Salt> --node-url <key> --gas-price 1

:bulb: Note: Salt is 0x00000000000000000000000000000000 by default. If you do not want to pass a salt manually, you can also use the --random-salt flag to randomise your salt as below:
forc deploy --random-salt --node-url <key> --gas-price 1

8 Likes

Okay, it sounds like you are running into an issue when trying to redeploy a contract using the forc tool. If I understand correctly, you’re trying to pass a --salt parameter to your deploy script, but encountering an error.

First, make sure that you have the latest version of forc installed, as the --salt option was only recently added. You can try running cargo install forc to install the latest version.

If you still encounter issues, double check that you’re passing the correct format for the --salt parameter. It should be a string of 32 hexadecimal characters, starting with “0x”. For example: --salt 0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890

Finally, make sure that you’re passing all of the required parameters to the deploy script, including the --node-url and --gas-price options.

If you continue to experience issues after trying these steps, please provide more information about the specific error message you’re receiving, and we can work from there to troubleshoot further.

1 Like