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

get_asset

Extract the asset from a monetary value with the experimental get_asset function.

Numscript

Requires flag: experimental-get-asset-function

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.

Returns the asset part of a monetary value.

numscript
#![feature("experimental-mid-script-function-call", "experimental-get-asset-function")]
vars {
  monetary $payment
  asset $asset = get_asset($payment)
}

send $payment (
  source = @world
  destination = @users:1234
)

set_tx_meta("currency", $asset)

With $payment = [EUR/2 5000], $asset resolves to EUR/2.

Use cases#

  • Store the asset of a dynamic monetary variable in transaction metadata
  • Route transactions differently based on currency
  • Validate asset type before processing