Running scripts

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 script_abigen! macro, which is similar to the abigen! macro seen previously.

    // The abigen is used for the same purpose as with contracts (Rust bindings)
    script_abigen!(
        MyScript,
        "packages/fuels/tests/scripts/script_with_arguments/out/debug/script_with_arguments-abi.json"
    );
    let wallet = launch_provider_and_get_wallet().await;
    let bin_path =
        "../fuels/tests/scripts/script_with_arguments/out/debug/script_with_arguments.bin";
    let instance = MyScript::new(wallet, bin_path);

    let bim = Bimbam { val: 90 };
    let bam = SugarySnack {
        twix: 100,
        mars: 1000,
    };
    let result = instance.main(bim, bam).call().await?;
    let expected = Bimbam { val: 2190 };
    assert_eq!(result.value, expected);

Running scripts with transaction parameters

The method for passing transaction parameters is the same as with contracts. As a reminder, the workflow would look like this:

    let parameters = TxParameters {
        gas_price: 1,
        gas_limit: 10000,
        ..Default::default()
    };
    let result = instance.main(a, b).tx_params(parameters).call().await?;

Logs

Script calls provide the same logging functions, get_logs() and get_logs_with_type<T>(), as contract calls. As a reminder, the workflow looks like this:

    script_abigen!(
        log_script,
        "packages/fuels/tests/logs/script_logs/out/debug/script_logs-abi.json"
    );

    let wallet = launch_provider_and_get_wallet().await;
    let bin_path = "../fuels/tests/logs/script_logs/out/debug/script_logs.bin";
    let instance = log_script::new(wallet.clone(), bin_path);

    let response = instance.main().call().await?;

    let logs = response.get_logs()?;
    let log_u64 = response.get_logs_with_type::<u64>()?;