{
  "$schema": "../rpc-schema-draft.json",
  "type": "object",
  "rpc": "listhtlcs",
  "title": "Command for querying HTLCs",
  "description": [
    "The **listhtlcs** RPC command gets all HTLCs (which, generally, we remember for as long as a channel is open, even if they've completed long ago)."
  ],
  "categories": [
    "readonly"
  ],
  "request": {
    "required": [],
    "additionalProperties": false,
    "properties": {
      "id": {
        "type": "string",
        "description": [
          "A short channel id (e.g. 1x2x3) or full 64-byte hex channel id, it will only list htlcs for that channel (which must be known)."
        ]
      },
      "index": {
        "type": "string",
        "added": "v25.05",
        "enum": [
          "created",
          "updated"
        ],
        "description": [
          "This controls the ordering of results."
        ],
        "default": "`created`"
      },
      "start": {
        "type": "u64",
        "added": "v25.05",
        "description": [
          "If `index` is specified, `start` may be specified to start from that value, which is generally returned from lightning-wait(7)."
        ]
      },
      "limit": {
        "type": "u32",
        "added": "v25.05",
        "description": [
          "If `index` is specified, `limit` can be used to specify the maximum number of entries to return."
        ]
      }
    }
  },
  "response": {
    "required": [
      "htlcs"
    ],
    "additionalProperties": false,
    "properties": {
      "htlcs": {
        "type": "array",
        "items": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "created_index",
            "short_channel_id",
            "id",
            "expiry",
            "direction",
            "amount_msat",
            "payment_hash",
            "state"
          ],
          "properties": {
            "short_channel_id": {
              "type": "short_channel_id",
              "description": [
                "The channel that contains/contained the HTLC."
              ]
            },
            "created_index": {
              "added": "v25.05",
              "type": "u64",
              "description": [
                "1-based index indicating order this htlc was created in."
              ]
            },
            "updated_index": {
              "added": "v25.05",
              "type": "u64",
              "description": [
                "1-based index indicating order this htlc was changed (only present if it has changed since creation)."
              ]
            },
            "id": {
              "type": "u64",
              "description": [
                "The unique, incrementing HTLC id the creator gave this."
              ]
            },
            "expiry": {
              "type": "u32",
              "description": [
                "The block number where this HTLC expires/expired."
              ]
            },
            "amount_msat": {
              "type": "msat",
              "description": [
                "The value of the HTLC."
              ]
            },
            "direction": {
              "type": "string",
              "enum": [
                "out",
                "in"
              ],
              "description": [
                "Out if we offered this to the peer, in if they offered it."
              ]
            },
            "payment_hash": {
              "type": "hash",
              "description": [
                "Payment hash sought by HTLC."
              ]
            },
            "state": {
              "type": "string",
              "enum": [
                "SENT_ADD_HTLC",
                "SENT_ADD_COMMIT",
                "RCVD_ADD_REVOCATION",
                "RCVD_ADD_ACK_COMMIT",
                "SENT_ADD_ACK_REVOCATION",
                "RCVD_REMOVE_HTLC",
                "RCVD_REMOVE_COMMIT",
                "SENT_REMOVE_REVOCATION",
                "SENT_REMOVE_ACK_COMMIT",
                "RCVD_REMOVE_ACK_REVOCATION",
                "RCVD_ADD_HTLC",
                "RCVD_ADD_COMMIT",
                "SENT_ADD_REVOCATION",
                "SENT_ADD_ACK_COMMIT",
                "RCVD_ADD_ACK_REVOCATION",
                "SENT_REMOVE_HTLC",
                "SENT_REMOVE_COMMIT",
                "RCVD_REMOVE_REVOCATION",
                "RCVD_REMOVE_ACK_COMMIT",
                "SENT_REMOVE_ACK_REVOCATION"
              ],
              "description": [
                "The first 10 states are for `out`, the next 10 are for `in`."
              ]
            }
          }
        }
      }
    }
  },
  "author": [
    "Rusty Russell [rusty@rustcorp.com.au](mailto:rusty@rustcorp.com.au) is mainly responsible."
  ],
  "see_also": [
    "lightning-listforwards(7)"
  ],
  "resources": [
    "Main web site: [https://github.com/ElementsProject/lightning](https://github.com/ElementsProject/lightning)"
  ],
  "examples": [
    {
      "request": {
        "id": "example:listhtlcs#1",
        "method": "listhtlcs",
        "params": [
          "109x1x1"
        ]
      },
      "response": {
        "htlcs": [
          {
            "created_index": 1,
            "updated_index": 9,
            "short_channel_id": "109x1x1",
            "id": 0,
            "expiry": 126,
            "direction": "out",
            "amount_msat": 500000000,
            "payment_hash": "paymenthashdelpay10101010101010101010101010101010101010101010101",
            "state": "RCVD_REMOVE_ACK_REVOCATION"
          },
          {
            "created_index": 2,
            "updated_index": 18,
            "short_channel_id": "109x1x1",
            "id": 1,
            "expiry": 135,
            "direction": "out",
            "amount_msat": 10001,
            "payment_hash": "paymenthashinvl0310031003100310031003100310031003100310031003100",
            "state": "RCVD_REMOVE_ACK_REVOCATION"
          },
          {
            "created_index": 3,
            "updated_index": 27,
            "short_channel_id": "109x1x1",
            "id": 2,
            "expiry": 149,
            "direction": "out",
            "amount_msat": 10001,
            "payment_hash": "paymenthashkey01k101k101k101k101k101k101k101k101k101k101k101k101",
            "state": "RCVD_REMOVE_ACK_REVOCATION"
          },
          {
            "created_index": 4,
            "updated_index": 36,
            "short_channel_id": "109x1x1",
            "id": 3,
            "expiry": 155,
            "direction": "out",
            "amount_msat": 10000202,
            "payment_hash": "paymenthashkey02k201k201k201k201k201k201k201k201k201k201k201k201",
            "state": "RCVD_REMOVE_ACK_REVOCATION"
          },
          {
            "created_index": 5,
            "updated_index": 44,
            "short_channel_id": "109x1x1",
            "id": 4,
            "expiry": 152,
            "direction": "out",
            "amount_msat": 10001,
            "payment_hash": "paymenthashkey03k301k301k301k301k301k301k301k301k301k301k301k301",
            "state": "RCVD_REMOVE_ACK_REVOCATION"
          }
        ]
      }
    },
    {
      "request": {
        "id": "example:listhtlcs#2",
        "method": "listhtlcs",
        "params": {
          "index": "created",
          "start": 4,
          "limit": 1
        }
      },
      "response": {
        "htlcs": [
          {
            "created_index": 4,
            "updated_index": 36,
            "short_channel_id": "109x1x1",
            "id": 3,
            "expiry": 155,
            "direction": "out",
            "amount_msat": 10000202,
            "payment_hash": "paymenthashkey02k201k201k201k201k201k201k201k201k201k201k201k201",
            "state": "RCVD_REMOVE_ACK_REVOCATION"
          }
        ]
      }
    }
  ]
}
