Operators Reference¶
Standard Operators¶
| Operators | Operands | |
|---|---|---|
| Equality[1] | == != |
Any |
| Comparison[1] | < > <= >= |
Int | Float |
| Arithmetic[1] | + - * / ** % |
Int | Float |
| Logical | && || ! |
Bool |
| Concatenation[2] | + |
String | Bytes | Array |
Access Operators¶
| Operator | | Operands | Examples | |
|---|---|---|---|---|
| Index Access[1] | . |
Array . IntArrayLike . Int |
$arr.0$arr.0.5$arr.$i$arr.{$i+1} |
|
| Field Access[2] | -> |
Any -> IdentifierAny -> { Expr } |
$tx->inputs$tx->{"inputs"}$tx->inputs.1->witness |
|
-
Index access (
.) is supported on arrays and array-like types:Bytes,Stringand multi-pathPubKey|SecKey|Descriptor. The index can be any integer expression. -
Field access (
->) is supported on the native types listed here as well as on tagged arrays:Field access is typically used with literal string keys, using the
$v->key_namesyntax. 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 @ PolicyInt @ 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 && PolicyPolicy || PolicyInt of Array<Policy> |
pk($a) && pk($b) → and(pk($a), pk($b))$pk1 || $pk2 || $pk3 → thresh(1, $pk1, $pk2, $pk3)2 of [ $pk1, $pk2, $pk3 ] → thresh(2, $pk1, $pk2, $pk3) |
Combine PSBT + |
Psbt + Psbt |
$psbt1+$psbt2 → psbt::combine[$psbt1, $psbt2] |
Taproot Tweak[2] + |
PubKey + ScriptPubKey + PolicyPubKey + ArrayPubKey + 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.
-
&&and||support >2 branches by translating them into anN-of-Nor1-of-Nthresh()policy. The Miniscript Policy standard forand()/or()only supports 2 branches.Compatible operands are coerced into a
Policy, so for example$alice && $bob→pk($alice) && pk($bob). -
Taproot tweak (
+) returns aDescriptor<Tr>or aTapInfo, depending on whether Miniscript or raw Script was used. Seetr()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:
-
OutPointas atxid:vouttuple -
TxOutas ascriptPubKey:amounttuplewpkh($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", 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]orA:B. It should typically get it right, but it could be surprising. For example,1:2is re-formatted as[1,2].
Operator Precedence¶
TDD