Passing Arguments
Learn how to pass arguments to your scripts from the command line
Acton allows you to pass arguments from the command line to your Tolk scripts.
Argument parsing is driven by the ABI for main(), so the values you
pass are interpreted according to the parameter types declared in the script.
Basic Argument Passing
To define a script that accepts arguments, add parameters to your main()
function. Acton maps one command-line argument to one main() parameter, in
order.
For example, consider a script that adds two numbers:
import "@acton/io"
fun main(a: int, b: int) {
println("The sum is: {}", a + b);
}You can run this script and pass the arguments as follows:
acton script add.tolk 10 20The output will be:
The sum is:
30How Parsing Works
Acton reads the ABI for main() and parses the forwarded CLI values
against those parameter types.
- The number of CLI arguments must exactly match the number of
main()parameters. - Arguments are positional.
- Parsing is type-aware. A value like
10can be interpreted differently depending on whether the parameter type isint,string, orcell.
If a shell argument contains spaces or square brackets, quote it so your shell passes it as a single value.
Nullable Values
Use null for supported nullable types:
import "@acton/io"
fun main(value: int?) {
println("Value: {}", value);
}Run it with:
# Pass null
acton script process_optional.tolk null
# Pass an actual value
acton script process_optional.tolk 42null is the supported null literal for script arguments.
Arrays
Arrays are written as [item1, item2]:
import "@acton/io"
fun main(items: array<int>) {
println("Count: {}", items.size());
println("First: {}", items.get(0));
println("Sum: {}", items.get(0) + items.get(1) + items.get(2));
}Run it with:
acton script process_array.tolk "[10 20 30]"Strings
Simple strings can be passed as ordinary shell arguments:
import "@acton/io"
fun main(name: string) {
println("Hello, {}", name);
}Execute it with:
acton script hello_string.tolk WorldOutput:
Hello, WorldIf you need escape sequences or exact whitespace, pass a quoted string literal to Acton:
acton script hello_string.tolk '"hello\nworld"'Shell quoting and Acton parsing are separate concerns. Use normal shell
quoting for spaces, and preserve the inner double quotes only when you want
Acton to parse escape sequences such as \n.
Cells, Slices, and bitsN
cell, slice, and bitsN arguments use plain Bag of Cells hex.
import "@acton/io"
fun main(data: cell) {
val s = data.beginParse();
val value = s.loadUint(32);
println("Value from cell: {}", value);
}First, create a cell with some data and get its hex representation. Then, run the script:
# Example with a cell containing a 32-bit integer 999
acton script process_cell.tolk b5ee9c72...For bitsN, pass the same plain BoC hex format you would pass for a slice.
Addresses
Use a normal TON address string for address, and null or an address for
address?:
import "@acton/io"
fun main(owner: address, backup: address?) {
println("Owner: {}", owner);
println("Backup: {}", backup);
}acton script process_address.tolk EQBvDB_H7FFBs0nF4ap_DBdcOrwY_rMIpNVVOR6SWYFHByMJ nullUnsupported Types
The script CLI does not currently accept every ABI type directly.
These parameter types are rejected:
tuplemapanddictbuilderany_address- structs, aliases, unions,
unknown, andlisp_list
Last updated on