Skip to content

Welcome to Minsc

A mini scripting language, library and experimentation playground for Bitcoin

Minsc is a high-level, domain-specific, embeddable language for Bitcoin scripting that simplifies the creation and fulfillment of complex spending conditions and transaction flows, using a simple, expressive, pseudo-code-like syntax.

The language is dynamically typed, functional and immutable. It can be run as a standalone program, or used as a library within an embedded host environment (currently JS/WASM, Python or Rust).

Get Started Playground

Why Minsc?

  • Learn Bitcoin concepts, data structures and contract design patterns
  • Build & Prototype apps with advanced Bitcoin contracts and multi-transaction spending flows
  • Integrate into your codebase as an embedded library (JS/WASM, Python or Rust)
  • Communicate scripting ideas clearly and succinctly β€” for education, research and collaboration
  • Experiment with new features, opcodes and covenant designs β€” like vaults, payment pools and more
  • Inspect & Manipulate transactions, scripts, descriptors and other Bitcoin primitives on the live playground

Code Examples

// Generate address from wpkh() descriptor
$sk = xprv9s21ZrQH143K2oa8UwybFKopmuLYDP9Qsvs18L1r14f23cDbjhCon777JEE83Rp88h2fqqZdEem5uG2qN9bhRJyNJMZW5LNy8xXiq39LL8b;
$address = address(wpkh($sk/0'/0/0)); // first receive address at m/0'/0/0

// Create, sign, finalize & extract PSBT
$psbt = psbt[
  "input": [
    "prevout": b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c:1,
    "utxo": wpkh($sk/0'/0/0):0.3 BTC,
  ],
  "outputs": [
    tb1qs2xpw2sc6vrl8u0x5mw2l9ff2tj4tsca82nq9w:0.0499 BTC,
    wpkh($sk/0'/1/0):0.25 BTC, // change to m/0'/1/0
    `OP_RETURN "Hello Minsc!"`:0,
  ],
];
$tx_signed = psbt::sign_extract($psbt, $sk);
$tx_hex = hex($tx_signed);
$sk = xprv9s21ZrQH143K2oa8UwybFKopmuLYDP9Qsvs18L1r14f23cDbjhCon777JEE83Rp88h2fqqZdEem5uG2qN9bhRJyNJMZW5LNy8xXiq39LL8b // seckey

$address = tb1qksxfxxcu0sc4tkg22zxrtlhffjf7qdsdwl5k8y // address

$psbt = psbt[
  "unsigned_tx": tx[
    "version": 2,
    "inputs": [
      b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c:1
    ],
    "outputs": [
      tb1qs2xpw2sc6vrl8u0x5mw2l9ff2tj4tsca82nq9w:0.0499 BTC,
      tb1qd2gnlp8wsy77v4mgedcjxh45glfual2ntakk4w:0.25 BTC,
      `OP_RETURN <0x48656c6c6f204d696e736321>`:0 BTC
    ]
  ],
  "version": 0,
  "inputs": [
    [
      "witness_utxo": tb1qksxfxxcu0sc4tkg22zxrtlhffjf7qdsdwl5k8y:0.3 BTC,
      "bip32_derivation": [
        [7f61f8b4/0'/0/0]0254dcc338e5a7abe253db970ef05d1afcb114229333735a0f343a0043011a3cab
      ]
    ]
  ],
  "outputs": [
    [ ],
    [ "bip32_derivation": [ [7f61f8b4/0'/1/0]02c6ec64d9f30e4262ede4f33949d224928e4291b6c47e692b3bb548b19866cd2c ] ],
    [ ]
  ]
] // psbt

$tx_signed = tx[
  "version": 2,
  "inputs": [
    [
      "prevout": b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c:1,
      "witness": [ 0x3045022100cc926aeb77d5d46fc8ace453066c4a2fe9ac8d7432e0d866b6ec1d0195b820b902204897619942703b40783340d28fad99703d1916c47f32d3ff8b950d57e71d286901, 0x0254dcc338e5a7abe253db970ef05d1afcb114229333735a0f343a0043011a3cab ]
    ]
  ],
  "outputs": [
    tb1qs2xpw2sc6vrl8u0x5mw2l9ff2tj4tsca82nq9w:0.0499 BTC,
    tb1qd2gnlp8wsy77v4mgedcjxh45glfual2ntakk4w:0.25 BTC,
    `OP_RETURN <0x48656c6c6f204d696e736321>`:0 BTC
  ]
] // transaction

$tx_hex = "020000000001014c94e48a870b85f41228d33cf25213dfcc8dd796e7211ed6b1f9a014809dbbb50100000000ffffffff0330244c0000000000160014828c172a18d307f3f1e6a6dcaf952952e555c31d40787d01000000001600146a913f84ee813de65768cb71235eb447d3cefd5300000000000000000e6a0c48656c6c6f204d696e73632102483045022100cc926aeb77d5d46fc8ace453066c4a2fe9ac8d7432e0d866b6ec1d0195b820b902204897619942703b40783340d28fad99703d1916c47f32d3ff8b950d57e71d286901210254dcc338e5a7abe253db970ef05d1afcb114229333735a0f343a0043011a3cab00000000" // string

See the Simple Signing Recipe or explore the other Cookbook Recipes for more complete examples.

$alice_sk = xprv9s21ZrQH143K3cknSUWpHBYiMp2pzLsK2FnyvjQhTmAuDHJxjhbtgmRsfic8KGpfBhJK5TJ9TXj6QRCHhkaMYSKzfaLAp9REp6qHwQ9t7rq;
$bob_sk = xprv9s21ZrQH143K2ntP27nrDJrZAyCxR6eYbyoJ3YYmwFg7gGsck2gDychpPRjsFSJBjZ3ajDZaYRzJup3UvTWCTsQjxiUt9jESPpUwJb4wwt6;
$alice = pubkey($alice_sk), $bob = pubkey($bob_sk);

// Setup a wsh() descriptor for a 2-of-2 multisig
$multisig = wsh($alice/* && $bob/*);
$address = address($multisig/0); // first address at m/0

// Create PSBT spending from $address
$psbt = psbt[
  "input": [
    "prevout": a2877bd944be3433d5030ef102922e52f7c40de8b5ca26fa8b7c724d341e936e:1,
    "utxo": ($multisig/0):0.5 BTC,
  ],
  "outputs": [
    tb1q3x0krlxcmnkfrc70x5xf5zluxtlddlu7dqepxa:0.4 BTC,
    ($multisig/1):0.099 BTC, // change back to multisig at m/1
  ],
];
// Sign, combine, finalize & extract
$psbt_signed = psbt::sign($psbt, $alice_sk) + psbt::sign($psbt, $bob_sk);
$tx_signed = psbt::finalize_extract($psbt_signed);
$tx_bytes = bytes($tx_signed);
$alice_sk = xprv9s21ZrQH143K3cknSUWpHBYiMp2pzLsK2FnyvjQhTmAuDHJxjhbtgmRsfic8KGpfBhJK5TJ9TXj6QRCHhkaMYSKzfaLAp9REp6qHwQ9t7rq // seckey

$bob_sk = xprv9s21ZrQH143K2ntP27nrDJrZAyCxR6eYbyoJ3YYmwFg7gGsck2gDychpPRjsFSJBjZ3ajDZaYRzJup3UvTWCTsQjxiUt9jESPpUwJb4wwt6 // seckey

$alice = xpub661MyMwAqRbcG6qFYW3peKVSuqsKPobAPUiaj7pK26ht65e7HEv9EZkMWyxXmEAXAK6uXBafzD7yNCS1FsGiHD3aQxiGhAtRfjtLLwadWUX // pubkey

$bob = xpub661MyMwAqRbcFGxr89KraSoHj13SpZNPyCitqvxPVbD6Z5CmHZzUXR2JEhdaiTsLbeet9tN4cUncZW4WqDb4MzyHgWix2VhTUhRygkDcFUr // pubkey

$multisig = wsh(and_v(v:pk(xpub661MyMwAqRbcG6qFYW3peKVSuqsKPobAPUiaj7pK26ht65e7HEv9EZkMWyxXmEAXAK6uXBafzD7yNCS1FsGiHD3aQxiGhAtRfjtLLwadWUX/*),pk(xpub661MyMwAqRbcFGxr89KraSoHj13SpZNPyCitqvxPVbD6Z5CmHZzUXR2JEhdaiTsLbeet9tN4cUncZW4WqDb4MzyHgWix2VhTUhRygkDcFUr/*))) // descriptor

$address = tb1qhreuv4em88l0xxrpwkpx50qtayx03d6gmw34wy7e3gr4acyxte7qxvjnx4 // address

$psbt = psbt[
  "unsigned_tx": tx[
    "version": 2,
    "inputs": [
      a2877bd944be3433d5030ef102922e52f7c40de8b5ca26fa8b7c724d341e936e:1
    ],
    "outputs": [
      tb1q3x0krlxcmnkfrc70x5xf5zluxtlddlu7dqepxa:0.4 BTC,
      tb1q3tekx7lp00dkcc8mh5le03xrqkmeph4tu9valum6ut3d2zpey82qcglf3g:0.099 BTC
    ]
  ],
  "version": 0,
  "inputs": [
    [
      "witness_utxo": tb1qhreuv4em88l0xxrpwkpx50qtayx03d6gmw34wy7e3gr4acyxte7qxvjnx4:0.5 BTC,
      "witness_script": `<0x02519b05299ba4380f9158efb7eb053a9e5c4e559d6c49e1cc2bbf98c2503f06c4> OP_CHECKSIGVERIFY <0x0203e1d6adb63bd3ef8fb92bb3b08cf1d243d999c819c84888469662eb280ce63d> OP_CHECKSIG`,
      "bip32_derivation": [
        [45b0d775/0]0203e1d6adb63bd3ef8fb92bb3b08cf1d243d999c819c84888469662eb280ce63d,
        [2dc70085/0]02519b05299ba4380f9158efb7eb053a9e5c4e559d6c49e1cc2bbf98c2503f06c4
      ]
    ]
  ],
  "outputs": [
    [ ],
    [
      "witness_script": `<0x039327059020f4c03dbe8f2ed28709a90da55c2e3f0636a798565f9555bff04f55> OP_CHECKSIGVERIFY <0x02b1cce860e9285079bc59b61e35d07fc3a75f25ee74abdff1e6894fc9ade617e2> OP_CHECKSIG`,
      "bip32_derivation": [
        [45b0d775/1]02b1cce860e9285079bc59b61e35d07fc3a75f25ee74abdff1e6894fc9ade617e2,
        [2dc70085/1]039327059020f4c03dbe8f2ed28709a90da55c2e3f0636a798565f9555bff04f55
      ]
    ]
  ]
] // psbt

$psbt_signed = psbt[
  "unsigned_tx": tx[
    "version": 2,
    "inputs": [
      a2877bd944be3433d5030ef102922e52f7c40de8b5ca26fa8b7c724d341e936e:1
    ],
    "outputs": [
      tb1q3x0krlxcmnkfrc70x5xf5zluxtlddlu7dqepxa:0.4 BTC,
      tb1q3tekx7lp00dkcc8mh5le03xrqkmeph4tu9valum6ut3d2zpey82qcglf3g:0.099 BTC
    ]
  ],
  "version": 0,
  "inputs": [
    [
      "witness_utxo": tb1qhreuv4em88l0xxrpwkpx50qtayx03d6gmw34wy7e3gr4acyxte7qxvjnx4:0.5 BTC,
      "partial_sigs": [
        0203e1d6adb63bd3ef8fb92bb3b08cf1d243d999c819c84888469662eb280ce63d: 0x30440220366da126306d2c66a06bfd94e29a8f61f1bb70ffe42971c73cae846f22dde55e022033c5b295a8d4aa824e04d82ee8853d11007e39d4df1844de8844cda8779d36a401,
        02519b05299ba4380f9158efb7eb053a9e5c4e559d6c49e1cc2bbf98c2503f06c4: 0x3044022043560ce2b789b76137e6e86dfa5226f33a527f999a557cab62843c31edce03a402202d9731831ade857b46b01af2911adf75d332054072d31772c9cd666f89c6647101
      ],
      "witness_script": `<0x02519b05299ba4380f9158efb7eb053a9e5c4e559d6c49e1cc2bbf98c2503f06c4> OP_CHECKSIGVERIFY <0x0203e1d6adb63bd3ef8fb92bb3b08cf1d243d999c819c84888469662eb280ce63d> OP_CHECKSIG`,
      "bip32_derivation": [
        [45b0d775/0]0203e1d6adb63bd3ef8fb92bb3b08cf1d243d999c819c84888469662eb280ce63d,
        [2dc70085/0]02519b05299ba4380f9158efb7eb053a9e5c4e559d6c49e1cc2bbf98c2503f06c4
      ]
    ]
  ],
  "outputs": [
    [ ],
    [
      "witness_script": `<0x039327059020f4c03dbe8f2ed28709a90da55c2e3f0636a798565f9555bff04f55> OP_CHECKSIGVERIFY <0x02b1cce860e9285079bc59b61e35d07fc3a75f25ee74abdff1e6894fc9ade617e2> OP_CHECKSIG`,
      "bip32_derivation": [
        [45b0d775/1]02b1cce860e9285079bc59b61e35d07fc3a75f25ee74abdff1e6894fc9ade617e2,
        [2dc70085/1]039327059020f4c03dbe8f2ed28709a90da55c2e3f0636a798565f9555bff04f55
      ]
    ]
  ]
] // psbt

$tx_signed = tx[
  "version": 2,
  "inputs": [
    [
      "prevout": a2877bd944be3433d5030ef102922e52f7c40de8b5ca26fa8b7c724d341e936e:1,
      "witness": [ 0x30440220366da126306d2c66a06bfd94e29a8f61f1bb70ffe42971c73cae846f22dde55e022033c5b295a8d4aa824e04d82ee8853d11007e39d4df1844de8844cda8779d36a401, 0x3044022043560ce2b789b76137e6e86dfa5226f33a527f999a557cab62843c31edce03a402202d9731831ade857b46b01af2911adf75d332054072d31772c9cd666f89c6647101, 0x2102519b05299ba4380f9158efb7eb053a9e5c4e559d6c49e1cc2bbf98c2503f06c4ad210203e1d6adb63bd3ef8fb92bb3b08cf1d243d999c819c84888469662eb280ce63dac ]
    ]
  ],
  "outputs": [
    tb1q3x0krlxcmnkfrc70x5xf5zluxtlddlu7dqepxa:0.4 BTC,
    tb1q3tekx7lp00dkcc8mh5le03xrqkmeph4tu9valum6ut3d2zpey82qcglf3g:0.099 BTC
  ]
] // transaction

$tx_bytes = 0x020000000001016e931e344d727c8bfa26cab5e80dc4f7522e9202f10e03d53334be44d97b87a20100000000ffffffff02005a620200000000160014899f61fcd8dcec91e3cf350c9a0bfc32fed6ff9ee00f9700000000002200208af3637be17bdb6c60fbbd3f97c4c305b790deabe159dff37ae2e2d5083921d4034730440220366da126306d2c66a06bfd94e29a8f61f1bb70ffe42971c73cae846f22dde55e022033c5b295a8d4aa824e04d82ee8853d11007e39d4df1844de8844cda8779d36a401473044022043560ce2b789b76137e6e86dfa5226f33a527f999a557cab62843c31edce03a402202d9731831ade857b46b01af2911adf75d332054072d31772c9cd666f89c6647101462102519b05299ba4380f9158efb7eb053a9e5c4e559d6c49e1cc2bbf98c2503f06c4ad210203e1d6adb63bd3ef8fb92bb3b08cf1d243d999c819c84888469662eb280ce63dac00000000 // bytes

See the Simple Multisig Recipe or explore the other Cookbook Recipes for more complete examples.

// Create a Taproot tree with a CTV script leaf for each possible whitelisted destination address
$tr = tr(NUMS, [
  `ctv::hash[ "output": tb1qtk006y5n5y3gljm8vfgfyjj9apuxfahncydrm5:0.01 BTC ] OP_CTV`,
  `ctv::hash[ "output": tb1qs2xpw2sc6vrl8u0x5mw2l9ff2tj4tsca82nq9w:0.01 BTC ] OP_CTV`,
  `ctv::hash[ "output": tb1qegulj3g6kjg4xslxsh8a6znv78czc993zfdrju:0.01 BTC ] OP_CTV`,
]);
// Funds sent to this address can only be spent to 1 of the 3 whitelisted destinations
$address = address($tr, signet);

// Spend to one of the whitelisted destinations
fn spend_to($prevout, $output) = tx[
  "input": [
    "prevout": $prevout,
    "witness": tr::script_witness($tr, `ctv::hash[ "output": $output ] OP_CTV`),
  ],
  "output": $output,
];

$tx = spend_to(
  bb30697cc1444591e65482199b770ff0606895ab1ebee8791a04f6ac6da1e412:1,
  tb1qs2xpw2sc6vrl8u0x5mw2l9ff2tj4tsca82nq9w:0.01 BTC
);
$tx_hex = hex($tx);
$tr = tr(50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0, [
  [
    `<0x0994539150dacce951802a61b64d903fc0b4f9a7246d20c852901ee6348ad85e> OP_CHECKTEMPLATEVERIFY`,
    `<0x8e5b229bc31405c6d2c86367e683f111bb8cad763b9779dc659dbca7f7a84d05> OP_CHECKTEMPLATEVERIFY`
  ],
  `<0xf857c85c95f3d7bcd18f403c7d2de6405b4d26fc84f61ce59fe45fafaa6c1e17> OP_CHECKTEMPLATEVERIFY`
]) // tapinfo

$address = tb1pmh5t8egr9z4sa3ynutl6emuj57kkfqsuguzan2wpzz9dpxlxnpjsk4duuh // address

spend_to = fn spend_to($prevout, $output) // function

$tx = tx[
  "version": 2,
  "inputs": [
    [
      "prevout": bb30697cc1444591e65482199b770ff0606895ab1ebee8791a04f6ac6da1e412:1,
      "witness": [ 0x200994539150dacce951802a61b64d903fc0b4f9a7246d20c852901ee6348ad85eb3, 0xc150929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac07ac368962565b506ff9ac77cfeba57e68e3d7b13389607b8c15f15f837fb1fc24068651c2c38a98e4e03afd7cd16f047a61562281df0a9bc64106dd07141585d ]
    ]
  ],
  "outputs": [
    tb1qs2xpw2sc6vrl8u0x5mw2l9ff2tj4tsca82nq9w:0.01 BTC
  ]
] // transaction

$tx_hex = "0200000000010112e4a16dacf6041a79e8be1eab956860f00f779b198254e6914544c17c6930bb0100000000ffffffff0140420f0000000000160014828c172a18d307f3f1e6a6dcaf952952e555c31d0222200994539150dacce951802a61b64d903fc0b4f9a7246d20c852901ee6348ad85eb361c150929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac07ac368962565b506ff9ac77cfeba57e68e3d7b13389607b8c15f15f837fb1fc24068651c2c38a98e4e03afd7cd16f047a61562281df0a9bc64106dd07141585d00000000" // string

See the CTV Taproot Whitelist Recipe or explore the other Cookbook Recipes for more complete examples.

$alice = xprv9s21ZrQH143K3TMKbDNpCPQ9m97mb91sXS6KjrPewZuoeNbW2qk7N6QqT9bFpB1X6jhGS8NEBrMADdYZf8QfRMTcJZsfbokCCUyZ7SH8Mzy;
$bob = xprv9s21ZrQH143K3QE9eS1BpBMo44QjHMahavrB23JMyS1eRyij6rhYmq7C7vxZtBe3HUvCVrZcoDZ3vkPT4FxSJaLdyoodJYPzKBxVXRc42Ge;
$secret_preimage = 0x0101010101010101010101010101010101010101010101010101010101010101;
$secret_hash = hash::sha256($secret_preimage);

// HTLC policy in Taproot P2TR (two script leaves)
$redeem = pk($alice) && sha256($secret_hash);
$refund = pk($bob) && older(4 days);
$htlc = tr($redeem || $refund); // NUMS as the internal key
$address = address($htlc);

// Spend via the redeem path, signed by Alice and includes the $secret_preimage
$redeem_tx = psbt::sign_extract([
  "input": [
    "prevout": a0499e20c8def7c8f5b1c04db191a5fd9ee313300b76c1a63a8281d86c78cf48:1,
    "utxo": $htlc:1.5 BTC,
    "sha256_preimages": [ $secret_preimage ],
  ],
  "output": wpkh($alice):1.499 BTC,
], $alice);

// Spend via the refund path, signed by Bob after a timeout
$refund_tx = psbt::sign_extract([
  "input": [
    "prevout": a0499e20c8def7c8f5b1c04db191a5fd9ee313300b76c1a63a8281d86c78cf48:1,
    "utxo": $htlc:1.5 BTC,
    "sequence": 4 days,
  ],
  "output": tr($bob):1.499 BTC,
], $bob);
$alice = xprv9s21ZrQH143K3TMKbDNpCPQ9m97mb91sXS6KjrPewZuoeNbW2qk7N6QqT9bFpB1X6jhGS8NEBrMADdYZf8QfRMTcJZsfbokCCUyZ7SH8Mzy // seckey

$bob = xprv9s21ZrQH143K3QE9eS1BpBMo44QjHMahavrB23JMyS1eRyij6rhYmq7C7vxZtBe3HUvCVrZcoDZ3vkPT4FxSJaLdyoodJYPzKBxVXRc42Ge // seckey

$secret_preimage = 0x0101010101010101010101010101010101010101010101010101010101010101 // bytes

$secret_hash = 0x72cd6e8422c407fb6d098690f1130b7ded7ec2f7f5e1d30bd9d521f015363793 // bytes

$redeem = and(pk(xpub661MyMwAqRbcFwRnhEupZXLtKAxFzbjitf1vYEoGVuSnXAveaP4MutjKJSK6HLRA3hsoCWU9YDygQnaeYDJiuRhKx9J6cTgwQ2L4hyvLUZg),sha256(72cd6e8422c407fb6d098690f1130b7ded7ec2f7f5e1d30bd9d521f015363793)) // policy

$refund = and(pk(xpub661MyMwAqRbcFtJckTYCBKJXc6FDgpJYx9mmpRhyXmYdJn3seQ1oKdRfyDY1ZvHUNztqi7TyX4odsHb6GVvbiMQ4BRRrGzBe3ggku7HXvBK),older(4194979)) // policy

$htlc = tr(50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0,{and_v(v:pk(xpub661MyMwAqRbcFwRnhEupZXLtKAxFzbjitf1vYEoGVuSnXAveaP4MutjKJSK6HLRA3hsoCWU9YDygQnaeYDJiuRhKx9J6cTgwQ2L4hyvLUZg),sha256(72cd6e8422c407fb6d098690f1130b7ded7ec2f7f5e1d30bd9d521f015363793)),and_v(v:pk(xpub661MyMwAqRbcFtJckTYCBKJXc6FDgpJYx9mmpRhyXmYdJn3seQ1oKdRfyDY1ZvHUNztqi7TyX4odsHb6GVvbiMQ4BRRrGzBe3ggku7HXvBK),older(4194979))}) // descriptor

$address = tb1pd06rq2n6ycvzp7ay248jn59jp6waq4av6fas53gtuaszn7j54muq3e7uta // address

$redeem_tx = tx[
  "version": 2,
  "inputs": [
    [
      "prevout": a0499e20c8def7c8f5b1c04db191a5fd9ee313300b76c1a63a8281d86c78cf48:1,
      "witness": [ 0x0101010101010101010101010101010101010101010101010101010101010101, 0x3ad1810b2caf82a16ac118a0fcc2ab56148ad22167b6a237c9718e10cc006a504ac6a4672b95c8c5a374ce2f44c5fe5e998b54bd69b86fbf8c47b61fc580439b, 0x208e56d6ea2e87610823ac6e3f313f490459bac0a1aa56345377eb1d42ca8457efad82012088a82072cd6e8422c407fb6d098690f1130b7ded7ec2f7f5e1d30bd9d521f01536379387, 0xc150929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0e3c324babbed12243bac998393ac7eb7e66de642a4cdf6cae01f6de44110a9d1 ]
    ]
  ],
  "outputs": [
    tb1qqql34zd6k0duv6vfk960ym22rdfnukma2nsxyy:1.499 BTC
  ]
] // transaction

$refund_tx = tx[
  "version": 2,
  "inputs": [
    [
      "prevout": a0499e20c8def7c8f5b1c04db191a5fd9ee313300b76c1a63a8281d86c78cf48:1,
      "sequence": 345600 seconds,
      "witness": [ 0x666410427d149588dea5658baec9d6aef33270be5b42ccbd684700dcf3ca8f2b026ef8bcaa907f8a63ea0d8a8b5010b3bdedbfda8b37c8b41439e6b8e6a32f19, 0x2053e5b9ce0ddf07a59a110f2cd405b5568114053a659c250add97eb795a20ea49ad03a30240b2, 0xc150929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac071a15bfe14d1337cbd40a3e378dc67cf72e1128313382b1d66b87827a3a189b3 ]
    ]
  ],
  "outputs": [
    tb1p63y9nqf37mw42nrrqqleafcn6w46ndxvy0w6hd5llugz5lh5d3pq28kax4:1.499 BTC
  ]
] // transaction

See the HTLC Recipe or explore the other Cookbook Recipes for more complete examples.