Skip to content

Operators Reference

Standard Operators

Operators Operands
Equality[1] == != Any
Comparison[1] < > <= >= Int | Float
Arithmetic[1] + - * / ** % Int | Float
Logical && || ! Bool
Concatenation[2] + String | Bytes | Array
  1. Implicit coercion is never performed for comparisons or arithmetic. Mixing integers and floats requires explicit conversions.

    For example: 1.5 * float(101)

  2. When the LHS of + is a string, the RHS is coerced to a string.

    For example: print("Transaction:"+$tx);

Access Operators

Operator Operands Examples
Index Access[1] . Array . Int
ArrayLike . Int
$arr.0
$arr.0.5
$arr.$i
$arr.{$i+1}
Field Access[2] -> Any -> Identifier
Any -> { Expr }
$tx->inputs
$tx->{"inputs"}
$tx->inputs.1->witness
  1. Index access (.) is supported on arrays and array-like types: Bytes, String and multi-path PubKey|SecKey|Descriptor. The index can be any integer expression.

  2. Field access (->) is supported on the native types listed here as well as on tagged arrays:

    $tagged = [ "foo": 1, "bar": 2 ];
    $tagged->bar == 2
    

    Field access is typically used with literal string keys, using the $v->key_name syntax. To use an expression of any data type as the key, use $v->{key_expr} instead. For example: $v->{$key_var} or $v->{true}

    The parser currently requires some complex LHS expressions for -> to be wrapped in a { } block. For example: {["foo": 123]}->foo

Bitcoin Operators

Operator Operands Examples
BIP 32 Derivation
/
PubKey / Int
SecKey / Int '
PubKey / *
PubKey / Array
PubKey / Hash
xpub661MyMwAqRZ90rTa…bcFvZ98rNvB/5
$alice_sk/84'/0h/0'/1/*
$alice_sk/$account'/($i+1)
$alice/<0;1>/*
$alice/hash::sha256("pay-to-contract-hash")
Execution Probability
@
Int @ Policy
Int @ Script
wsh(2@pk($alice) || 1@pk($bob))
tr[ 2@`$a OP_CHECKSIG`, 1@`$b OP_CHECKSIG` ]
Script Repetition
*
Script * Int OP_CAT*2`OP_CAT OP_CAT`
`OP_DROP 3*`OP_ROT OP_ADD` OP_SUB`
Policy Composition[1]
&& || of
Policy && Policy
Policy || Policy
Int of Array<Policy>
pk($a) && pk($b)and(pk($a), pk($b))
$pk1 || $pk2 || $pk3thresh(1, $pk1, $pk2, $pk3)
2 of [ $pk1, $pk2, $pk3 ]thresh(2, $pk1, $pk2, $pk3)
Combine PSBT
+
Psbt + Psbt $psbt1+$psbt2psbt::combine[$psbt1, $psbt2]
Taproot Tweak[2]
+
PubKey + Script
PubKey + Policy
PubKey + Array
PubKey + Hash
NUMS+`<1 year> OP_CSV`tr(NUMS, `<1 year> OP_CSV`)
$alice+[ pk($b), pk($c) ]tr($alice, [ ])
$bob+0xcb40ac3f58…tr($bob, 0xcb40ac3f58…)

Unhardened child key derivation. Can also derive SecKey, Policy, Descriptor and Arrays of derivable types.

Hardened child key derivation. Also supported using h instead of '. Only possible on SecKey.

Enables the wildcard modifier. Supports /*' and /*h. Can also be used with SecKey.

Multi-path derivation. Supported using the <M;N;K> syntax or with standard arrays: $alice/<0;1>$alice/[0,1].

Can also derive SecKey, Policy, Descriptor and Arrays of derivable types.

Unhardened child key derivation using a 256-bit hash. Can also derive SecKey, Policy, Descriptor and Arrays of derivable types.

Tweak using the script tree merkle root hash. Returns a TapInfo that supports key-path spends only.

  1. && and || support >2 branches by translating them into an N-of-N or 1-of-N thresh() policy. The Miniscript Policy standard for and()/or() only supports 2 branches.

    Compatible operands are coerced into a Policy, so for example $alice && $bobpk($alice) && pk($bob).

  2. Taproot tweak (+) returns a Descriptor<Tr> or a TapInfo, depending on whether Miniscript or raw Script was used. See tr() for more information.

Colon Tuple Constructor

Operator Operands Example
Colon Tuple : Any : Any A:B[ A, B ]

The colon operator provides syntactic sugar for constructing 2-tuple arrays, using A:B as shorthand for [ A, B ].

It is commonly used in Minsc to represent simple 2-field data structures, such as:

  • OutPoint as a txid:vout tuple

    5e876d922f10e1b7382c72b850f1796d5259c62b72266fb995368ec859afb07e:1
    // → [ 5e876d922f10e1b7382c72b8…, 1 ]
    
  • TxOut as a scriptPubKey:amount tuple

    wpkh($alice):1.5 BTC // → [ wpkh($alice), 150000000 ]
    

It is also used for constructing "object"-like tagged arrays of key-value pairs. For example:

$tx = tx([
  "version": 2,
  "locktime": 1 day,
  "inputs": [
    [
      "prevout": 5e876d922f10e1b7382c72b850f1796d5259c62b72266fb995368ec859afb07e:0,
      "witness": [ 0x010203f0e0d0 ],
    ]
  ],
  "outputs": [
    wpkh($alice):1.5 BTC,
    bc1qu6p58lnd32acn0rpzkevk76c7g9aant6k4s2ly:9000,
  ]
]);
$tx = tx([
  [ "version", 2 ],
  [ "locktime", 4194473 ],
  [
    "inputs",
    [
      [
        [ "prevout", [ 0x5e876d922f10e1b7382c72b850f1796d5259c62b72266fb995368ec859afb07e, 0 ] ],
        [ "witness", [ 0x010203f0e0d0 ] ],
      ]
    ],
  ],
  [
    "outputs",
    [
      [ wpkh($alice), 150000000 ],
      [ bc1qu6p58lnd32acn0rpzkevk76c7g9aant6k4s2ly, 9000 ],
    ]
  ]
]);

Unlike all other operators in Minsc, the colon operator is right-associative. This makes line 6 in the last example parse as [ "prevout", [ 5e876d922f…, 0 ] ] rather than [ [ "prevout", 5e876d922f ], 0 ].

When 2-tuple arrays are formatted as strings (e.g. through str() or on the web playground), there's a heuristic that decides whether to format them as [A,B] or A:B. It should typically get it right, but it could be surprising. For example, 1:2 is re-formatted as [1,2] .

Operator Precedence

TDD