Contracts
Developers12.5.12+

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 #

GroupInstructions
IntrospectionThe inputs and outputs of the spending transaction: counts, values, scripts, commitments and states
ArithmeticOP_MUL, OP_MULDIV, OP_INVERT, OP_NUMEQUAL, OP_NUMEQUALVERIFY, OP_NUMNOTEQUAL
ChainOP_CHECKBLOCKHASHVERIFY, OP_CHECKPARENTHEADERVERIFY, OP_TXOUTPUTSROOT
ControlLoops (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, with scripttrace=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 #

Config
contractindex=1

The 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.

12.5.13+

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.

KindContract
betbet-…The outputs of the four modes of BetBet (Games)
launch-ledger, launch-curveA launch pool (Launch pools)
name, name-escrowA name and the escrow of a claim (Names)
bondA payer bond (Receipts)
alp-offer, escrow, counter, vault, claim-treeTemplates 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/v1Content
contracts?kind=&wallet=Contracts, latest activity first
contracts/<Q>, /utxos, /history, /rulesOne 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/statsTotals, the count by kind, rebuildNeeded
Source share/www/docs/contracts.md in the lotusd repository
Checked against doc/contracts/README.md doc/contracts/spec.md doc/contracts/spec-extensions.md doc/contracts/tooling.md doc/contracts/module.md