Here is what the Move paper says on transaction scripts:
Move adds flexibility to Libra via transaction scripts. Each Libra transaction includes a transaction script that is effectively the main procedure of the transaction. A transaction script is a single procedure that contains arbitrary Move code, which allows customizable transactions. A script can
invoke multiple procedures of modules published in the blockchain and perform local computation on the results. This means that scripts can perform either expressive one-off behaviors (such as paying a specific set of recipients) or reusable behaviors (by invoking a single procedure that encapsulates the reusable logic).
Essentially, a transaction script is like a main
procedure and modules are libraries of reusable code that the main
procedure can use.
But why dont we just define everything on the custom script ?
This question is somewhat similar to saying for (e.g.) Java: “why don’t we define everything in main
and not allow classes”?
- If there were only transaction scripts and no modules, it would not be possible to create custom resources or “smart contracts” (because scripts cannot define resources).
- If there were only modules and no transaction scripts, even code that the transaction submitter intends to execute a single time would need be published on the blockchain forever. This would discourage useful one-off behaviors.