What is salt, and how do I use it?

Salt is a unique random value that allows you to deploy contracts that are otherwise exactly the same and get different contract IDs. You can use deploy_with_parameters to configure the salt for a deployment.

use fuels::prelude::*;
use rand::prelude::{Rng, SeedableRng, StdRng};

abigen!(
  MyContract,
  "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;

let rng = &mut StdRng::seed_from_u64(2322u64);
let salt: [u8; 32] = rng.gen();

let contract_id = Contract::deploy_with_parameters(
   "../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
   &wallet,
   TxParameters::default(),
   StorageConfiguration::default(),
   Salt::from(salt),
)
.await?;
1 Like