docs/src/running-scripts.md
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.
{{#include ../../e2e/tests/scripts.rs:script_with_arguments}}
Furthermore, if you need to separate submission from value retrieval for any reason, you can do so as follows:
{{#include ../../e2e/tests/scripts.rs:submit_response_script}}
The method for passing transaction policies is the same as with contracts. As a reminder, the workflow would look like this:
{{#include ../../e2e/tests/scripts.rs:script_with_tx_policies}}
If you need to add specific inputs and outputs to script calls, you can use the with_inputs and with_outputs methods.
{{#include ../../e2e/tests/scripts.rs:script_custom_inputs_outputs}}
Note: if custom inputs include coins that need to be signed, use the
add_signermethod to add the appropriate signer.
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:
{{#include ../../e2e/tests/logs.rs:script_logs}}
Scripts use the same interfaces for setting external contracts as contract methods.
Below is an example that uses with_contracts(&[&contract_instance, ...]).
{{#include ../../e2e/tests/logs.rs:external_contract}}
And this is an example that uses with_contract_ids(&[&contract_id, ...]).
{{#include ../../e2e/tests/logs.rs:external_contract_ids}}
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.
{{#include ../../e2e/sway/scripts/script_configurables/src/main.sw}}
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.
{{#include ../../e2e/tests/configurables.rs:script_configurables}}