You can run a script using its JSON-ABI and the path to its binary file. You can run the scripts with arguments. For this, you have to use the abigen! macro seen previously .
// The abigen is used for the same purpose as with contracts (Rust bindings)abigen!(Script( name ="MyScript", abi ="packages/fuels/tests/scripts/arguments/out/debug/arguments-abi.json"));let wallet =launch_provider_and_get_wallet().await?;let bin_path ="../fuels/tests/scripts/arguments/out/debug/arguments.bin";let script_instance =MyScript::new(wallet, bin_path);let bim =Bimbam { val:90 };let bam =SugarySnack { twix:100, mars:1000,};let result = script_instance.main(bim, bam).call().await?;let expected =Bimbam { val:2190 };assert_eq!(result.value, expected);
Furthermore, if you need to separate submission from value retrieval for any reason, you can do so as follows:
let submitted_tx = script_instance.main(my_struct).submit().await?;let value = submitted_tx.response().await?.value;
The method for passing transaction policies is the same as with contracts . As a reminder, the workflow would look like this:
let tx_policies =TxPolicies::default().with_gas_price(1).with_script_gas_limit(1_000_000);let result = script_instance.main(a, b).with_tx_policies(tx_policies).call().await?;
Script calls provide the same logging functions, decode_logs() and decode_logs_with_type<T>(), as contract calls. As a reminder, the workflow looks like this:
Same as contracts, you can define configurable constants in scripts which can be changed during the script execution. Here is an example how the constants are defined.
Each configurable constant will get a dedicated with method in the SDK. For example, the constant STR_4 will get the with_STR_4 method which accepts the same type defined in sway. Below is an example where we chain several with methods and execute the script with the new constants.