Transactions

A transaction is a list of operations that execute atomically. This reference describes the JSON structure of commit requests.

Overview

All state changes flow through the /v1/commit endpoint as transactions. The write daemon validates, executes, and persists operations before returning a success response.

Structure

Commit Request

{
  "operations": [
    { "op": "OperationName", "args": { ... } },
    { "op": "AnotherOperation", "args": { ... } }
  ],
  "idempotency_key": "optional-unique-key",
  "metadata": {
    "custom_field": "optional user metadata"
  }
}

Operation Envelope

Each operation has the same envelope structure:

{
  "op": "OperationName",
  "args": {
    "field1": "value1",
    "field2": 123
  }
}

Fields

Request Fields

FieldTypeRequiredDescription
operationsarrayYesList of operations to execute
idempotency_keystringNoUnique key for deduplication
metadataobjectNoUser-defined metadata echoed in response

Operation Envelope Fields

FieldTypeRequiredDescription
opstringYesOperation identifier
argsobjectYesOperation-specific arguments

Response Fields

FieldTypeDescription
global_seqintegerGlobal sequence number of the commit
batch_seqintegerBatch sequence number
minted_instancesarrayIDs of instances created by MintInstance
metadataobjectEcho of request metadata including idempotency_key

Examples

Minimal Transaction

{
  "operations": [
    {
      "op": "CreateContainer",
      "args": {
        "container_id": 1001,
        "kind": "Standard",
        "owner": null
      }
    }
  ]
}

Transaction with Idempotency

{
  "operations": [
    {
      "op": "AddFungible",
      "args": {
        "container_id": 1001,
        "class_id": 100,
        "key": 1,
        "quantity": 500
      }
    }
  ],
  "idempotency_key": "add-balance-2024-01-15-001"
}

Multi-Operation Transaction

{
  "operations": [
    {
      "op": "RegisterClass",
      "args": {
        "request": {
          "class_id": 200,
          "name": "Sample",
          "fungible": false
        }
      }
    },
    {
      "op": "MintInstance",
      "args": {
        "class_id": 200,
        "key": 1
      }
    },
    {
      "op": "PlaceInSlot",
      "args": {
        "container_id": 1001,
        "instance_id": 9001,
        "slot_index": 0
      }
    }
  ],
  "metadata": {
    "experiment_id": "exp-001",
    "operator": "system"
  }
}

Response:

{
  "global_seq": 5,
  "batch_seq": 1,
  "minted_instances": [9001],
  "metadata": {
    "experiment_id": "exp-001",
    "operator": "system"
  }
}

Idempotent Retry Response

When the same idempotency key is sent again:

{
  "global_seq": 5,
  "batch_seq": 1,
  "minted_instances": [9001],
  "metadata": {
    "idempotency_key": "create-sample-001"
  }
}

The X-Asset-Idempotency: hit header indicates a cached response.