Preview. Stack v4.0 has not been released, and what is documented here can still change before it does. The current release is v3.2.Go to v3.2
Numscript

oneof

Select the first source or destination able to satisfy a transfer with experimental oneof.

Numscript

Requires flag: experimental-oneof

This is a feature of the experimental Numscript interpreter. To run it through the API, set runtime: experimental-interpreter in the transaction request body (the default is machine) and enable the relevant feature flag. See Selecting an Interpreter for per-feature availability.

Select the first source or destination that can satisfy the transaction. Unlike ordered sources (which split funds across accounts), oneof picks exactly one branch.

Source#

Try each account in order. The first one with sufficient balance handles the entire amount:

numscript
#![feature("experimental-oneof")]
send [USD/2 10000] (
  source = oneof {
    @users:1234:main
    @users:1234:savings
    @world
  }
  destination = @merchants:5678
)

If @users:1234:main has 10000 or more, it's used entirely. If not, @users:1234:savings is tried. Falls through to @world only if neither user account can cover the full amount.

This differs from ordered sources ({ @a @b @c }) which would drain @a first, then take the remainder from @b, then @c. With oneof, it's all-or-nothing per branch.

Destination#

numscript
#![feature("experimental-oneof")]
send [USD/2 10000] (
  source = @revenue
  destination = oneof {
    max [USD/2 5000] to @payouts:priority
    remaining to @payouts:standard
  }
)

The first matching constraint is used. max caps the amount for that branch; remaining catches everything else.