Contracts
Taproot contracts on Lotus: the instructions, the commands and tools, the contract index, the types it recognises and its routes.
A contract is a Taproot output whose leaf scripts say how it may be spent, with an optional 32-byte state. The scripts can read the transaction that spends them, so an output can require the next one: a counter, a vault, a pool or a game. The contract instructions are active from the contracts upgrade (12.5.12).
Instructions #
| Group | Instructions |
|---|---|
| Introspection | The inputs and outputs of the spending transaction: counts, values, scripts, commitments and states |
| Arithmetic | OP_MUL, OP_MULDIV, OP_INVERT, OP_NUMEQUAL, OP_NUMEQUALVERIFY, OP_NUMNOTEQUAL |
| Chain | OP_CHECKBLOCKHASHVERIFY, OP_CHECKPARENTHEADERVERIFY, OP_TXOUTPUTSROOT |
| Control | Loops (OP_BEGIN, OP_UNTIL) and functions (OP_DEFINE, OP_INVOKE), in Taproot scripts |
A leaf has a cost budget of (41 + the size of the input script) × 800, so every loop ends. Limits: Taproot. The bytes of a revealed script count in the price of on-chain data.
Commands and tools #
createcontract, decodecontract, contractstate, spendcontract and tracescript build, read and trace contracts. None of them signs or broadcasts. See JSON-RPC.
- Developers, Contract tools and Script trace in the web UI.
POST /api/v1/script/trace, withscripttrace=1(off by default).- In the lotusd sources: a script builder in TypeScript, a Python toolkit, a cost estimator, and shared test vectors.
The contract index #
contractindex=1The index is off by default. It follows every Taproot output by its commitment: the outputs, the state each one holds, how each was spent, and the state changes. It is read only and changes no rule.
The transactions of a block are read in dependency order, so spends inside one block are no longer missed, and contracts carry a type. The index is rebuilt once, at the first start, for this module only. A pruned node keeps its rows, and contracts/stats answers "rebuildNeeded": true.
Types #
kind names the template. kind_source says how it is known: from the record of the transaction that created it, a fixed commitment, a template with its parameters, or the shape of a revealed leaf. state_decoded gives the state as named fields, with the unit in the name.
| Kind | Contract |
|---|---|
betbet-… | The outputs of the four modes of BetBet (Games) |
launch-ledger, launch-curve | A launch pool (Launch pools) |
name, name-escrow | A name and the escrow of a claim (Names) |
bond | A payer bond (Receipts) |
alp-offer, escrow, counter, vault, claim-tree | Templates of the toolkit |
A commitment that is only ever spent by its key, with no state and no rule, is a wallet address: wallet is true. warnings names a known weakness of the revealed leaves.
Routes #
Route under /api/v1 | Content |
|---|---|
contracts?kind=&wallet= | Contracts, latest activity first |
contracts/<Q>, /utxos, /history, /rules | One contract: outputs, unspent outputs, state changes, revealed rules |
contracts/block/<height> | The state changes of a block |
contracts/tx/<txid> (12.5.13) | The contract outputs a transaction created and spent, and its state changes |
contracts/stats | Totals, the count by kind, rebuildNeeded |
