September 2023 Beta-4 Breaking Changes Update 🌴

Fuel Stack September Breaking Changes Update

This guide assumes you have already followed the beta-4 migration guide and are looking to bump to the latest version of the toolchain.

Sway

From now on, string literals produce the str slice type instead of the string array type. To convert between string arrays and slices, you can use the newly provided intrinsics.

/* BEFORE - v0.45.0 */
let my_string: str[4] = "fuel";

/* AFTER - v0.46.0 */
let my_string: str = "fuel";

If you use a function that needs a specific trait and you don’t import that trait, the compiler now will raise an error. This is because the compiler isn’t aware of the trait in the current context.

For the example below you would now get an error if the “Hash” trait for “u64” isn’t imported. To solve this, ensure you import the “Hash” trait.

/* BEFORE - v0.45.0 */
storage {
    item_map: StorageMap<u64, Item> = StorageMap {},
}

/* AFTER - v0.46.0 */
use std::{
    hash::Hash,
};

storage {
    item_map: StorageMap<u64, Item> = StorageMap {},
}

TS SDK

The addResourceInputsAndOutputs() function has been renamed to addResources(), streamlining its name.

/* BEFORE - v0.55.0 */
request.addResourceInputsAndOutputs(resources);

/* AFTER - v0.57.0 */
request.addResources(resources);

Similarly, addPredicateResourcesInputsAndOutputs() is now more concisely known as addPredicateResources().

The reason we have a distinct method for adding predicate resources is that the creation of predicate inputs mandates the presence of both the predicate’s bytes and data bytes. With these methods, there’s no longer a need to manually create and set up an instance of a ScriptTransactionRequest, simplifying the process further.

/* BEFORE - v0.55.0 */
const predicateInputs: TransactionRequestInput[] = predicateUtxos.map((utxo) => ({
  id: utxo.id,
  type: InputType.Coin,
  amount: utxo.amount,
  assetId: utxo.assetId,
  owner: utxo.owner.toB256(),
  txPointer: '0x00000000000000000000000000000000',
  witnessIndex: 0,
  maturity: 0,
  predicate: predicate.bytes,
  predicateData: predicate.predicateData,
}));

/* AFTER - v0.57.0 */
request.addPredicateResources(predicateUtxos, predicate.bytes, predicate.predicateData)

Rust SDK

The function calculate_base_amount_with_fee() currently returns a value of type Option<64>.

/* BEFORE - v0.47.0 */
let new_base_amount = calculate_base_amount_with_fee(&tb, &consensus_parameters, previous_base_amount)

/* AFTER - v0.48.0 */
let new_base_amount = calculate_base_amount_with_fee(&tb, &consensus_parameters, previous_base_amount)?

The function calculate_base_amount_with_fee() now returns a value of type Result<Option<TransactionFee>> instead of Option<TransactionFee>.

/* BEFORE - v0.47.0 */
let transaction_fee = tb.fee_checked_from_tx(consensus_params).expect("Error calculating TransactionFee");

/* AFTER - v0.48.0 */
let transaction_fee = tb.fee_checked_from_tx(consensus_params)?.ok_or(error!(InvalidData, "Error calculating TransactionFee"))?;

Storage slots are now automatically loaded in when using the default configuration.

/* BEFORE - v0.47.0 */
let storage_config =
StorageConfiguration::load_from("out/debug/contract-storage_slots.json").unwrap();

let load_config = LoadConfiguration::default().with_storage_configuration(storage_config);

let id = Contract::load_from(
    "./out/debug/contract.bin",
    load_config,
)
.unwrap()
.deploy(&wallet, TxParameters::default())
.await
.unwrap();

/* AFTER - v0.48.0 */
let id = Contract::load_from(
    "./out/debug/contract.bin",
    LoadConfiguration::default(),
)
.unwrap()
.deploy(&wallet, TxParameters::default())
.await
.unwrap();
4 Likes