Ana içerik geç

POST /api/chain/:slug/contracts

Create a contract from a JSON definition. The handler validates the definition against ContractDefinitionSchema (zod) and validateContractDefinition (operator-existence check), then inserts the row in contracts with current_state set to the initial state.

Auth

Bearer with operator role or higher on the target state machine.

Request

{
"name": "ProductionEscrow",
"version": "1.0",
"states": {
"pending": { "initial": true },
"funded": {},
"released": { "terminal": true }
},
"transitions": [
{ "from": "pending", "to": "funded", "operator": "NM26", "condition": "amount > 0" },
{ "from": "funded", "to": "released", "operator": "GR37", "condition": "buyer_signoff == true" }
]
}

The full schema (states, transitions, condition grammar) is documented at Contracts concept.

Response — 201

{
"ok": true,
"contract": {
"id": "uuid",
"originId": "zeq-dev:my-iot-fleet",
"name": "ProductionEscrow",
"version": "1.0",
"definition": { ... },
"currentState": "pending",
"createdBy": "ZEQ07491829374",
"createdAt": "2026-04-28T01:49:00Z",
"updatedAt": "2026-04-28T01:49:00Z"
}
}

Errors

StatusBodyCause
400{ ok: false, error: "..." }invalid definition (zod or operator-not-found)
401unauthorizedbearer missing
403forbiddenrole < operator
404not_foundslug doesn't resolve

Side effects

A row is appended to the audit entangled state (audit_log) with transition_type: "contract" to record the creation.