{
  "$schema": "../rpc-schema-draft.json",
  "type": "object",
  "rpc": "sendonion",
  "title": "Send a payment with a custom onion packet",
  "description": [
    "Note: you probably want to use the more modern and flexible `injectpaymentonion` command instead of this.",
    "The **sendonion** RPC command can be used to initiate a payment attempt with a custom onion packet. The onion packet is used to deliver instructions for hops along the route on how to behave. Normally these instructions are indications on where to forward a payment and what parameters to use, or contain details of the payment for the final hop. However, it is possible to add arbitrary information for hops in the custom onion, allowing for custom extensions that are not directly supported by Core Lightning.",
    "",
    "If the first element of *route* does not have \"channel\" set, a suitable channel (if any) will be chosen, otherwise that specific short-channel-id is used. The following is an example of a 3 hop onion:",
    "",
    "```json",
    "[",
    "  \"298606954e9de3e9d938d18a74fed794c440e8eda82e52dc08600953c8acf9c4\",",
    "  \"2dc094de72adb03b90894192edf9f67919cb2691b37b1f7d4a2f4f31c108b087\",",
    "  \"a7b82b240dbd77a4ac8ea07709b1395d8c510c73c17b4b392bb1f0605d989c85\"",
    "]",
    "```"
  ],
  "request": {
    "required": [
      "onion",
      "first_hop",
      "payment_hash"
    ],
    "additionalProperties": false,
    "properties": {
      "onion": {
        "type": "hex",
        "description": [
          "Hex-encoded 1366 bytes long blob that was returned by either of the tools that can generate onions. It contains the payloads destined for each hop and some metadata. Please refer to [BOLT 04][bolt04] for further details. If is specific to the route that is being used and the *payment_hash* used to construct, and therefore cannot be reused for other payments or to attempt a separate route. The custom onion can generally be created using the `devtools/onion` CLI tool, or the **createonion** RPC command."
        ]
      },
      "first_hop": {
        "type": "object",
        "description": [
          "Instructs Core Lightning which peer to send the onion to. It is a JSON dictionary that corresponds to the first element of the route array returned by *getroute* (so fields not mentioned here are ignored)."
        ],
        "required": [
          "id",
          "amount_msat",
          "delay"
        ],
        "additionalProperties": true,
        "properties": {
          "id": {
            "type": "pubkey",
            "description": [
              "Node id for the peer. Use any available channel available to this peer."
            ]
          },
          "amount_msat": {
            "type": "msat",
            "description": [
              "The amount to add an HTLC for millisatoshis."
            ]
          },
          "delay": {
            "type": "u16",
            "description": [
              "The number of blocks delay of blocks on top of the current blockheight."
            ]
          }
        }
      },
      "payment_hash": {
        "type": "hash",
        "description": [
          "Specifies the 32 byte hex-encoded hash to use as a challenge to the HTLC that we are sending. It is specific to the onion and has to match the one the onion was created with."
        ]
      },
      "label": {
        "type": "string",
        "description": [
          "Can be used to provide a human readable reference to retrieve the payment at a later time."
        ]
      },
      "shared_secrets": {
        "type": "array",
        "description": [
          "A JSON list of 32 byte hex-encoded secrets that were used when creating the onion. Core Lightning can send a payment with a custom onion without the knowledge of these secrets, however it will not be able to parse an eventual error message since that is encrypted with the shared secrets used in the onion. If *shared_secrets* is provided Core Lightning will decrypt the error, act accordingly, e.g., add a `channel_update` included in the error to its network view, and set the details in *listsendpays* correctly. If it is not provided Core Lightning will store the encrypted onion, and expose it in *listsendpays* allowing the caller to decrypt it externally. If it is not provided the Core Lightning node does not know how long the route is, which channels or nodes are involved, and what an eventual error could have been. It can therefore be used for oblivious payments."
        ],
        "items": {
          "type": "secret"
        }
      },
      "partid": {
        "type": "u16",
        "description": [
          "If provided and non-zero, allows for multiple parallel partial payments with the same *payment_hash*."
        ]
      },
      "bolt11": {
        "type": "string",
        "description": [
          "If provided, it will be returned in *waitsendpay* and *listsendpays* results."
        ]
      },
      "amount_msat": {
        "type": "msat",
        "description": [
          "Used to annotate the payment, and is returned by *waitsendpay* and *listsendpays*."
        ]
      },
      "destination": {
        "type": "pubkey",
        "description": [
          "If provided, it will be returned in **listpays** result."
        ]
      },
      "localinvreqid": {
        "type": "hash",
        "description": [
          "`localinvreqid` is used by offers to link a payment attempt to a local `invoice_request` offer created by lightningd-invoicerequest(7)."
        ]
      },
      "groupid": {
        "type": "u64",
        "description": [
          "Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash."
        ]
      },
      "description": {
        "added": "v0.11.0",
        "type": "string",
        "description": [
          "If provided, it will be returned in *waitsendpay* and *listsendpays* results."
        ]
      },
      "total_amount_msat": {
        "type": "msat",
        "description": [
          "This is the full amount requested by the destination in the invoice. It is needed internally for multi-part payments.",
          "Its default value is 0 msat for backwards compatibility."
        ],
        "default": "0",
        "added": "v25.05"
      }
    }
  },
  "response": {
    "required": [
      "created_index",
      "id",
      "payment_hash",
      "status",
      "created_at",
      "amount_sent_msat"
    ],
    "additionalProperties": true,
    "properties": {
      "created_index": {
        "added": "v23.11",
        "type": "u64",
        "description": [
          "1-based index indicating order this payment was created in."
        ]
      },
      "id": {
        "type": "u64",
        "description": [
          "Old synonym for created_index."
        ]
      },
      "payment_hash": {
        "type": "hash",
        "description": [
          "The hash of the *payment_preimage* which will prove payment."
        ]
      },
      "status": {
        "type": "string",
        "enum": [
          "pending",
          "complete"
        ],
        "description": [
          "Status of the payment (could be complete if already sent previously)."
        ]
      },
      "amount_msat": {
        "type": "msat",
        "description": [
          "The amount delivered to destination (if known)."
        ]
      },
      "destination": {
        "type": "pubkey",
        "description": [
          "The final destination of the payment if known."
        ]
      },
      "created_at": {
        "type": "u64",
        "description": [
          "The UNIX timestamp showing when this payment was initiated."
        ]
      },
      "amount_sent_msat": {
        "type": "msat",
        "description": [
          "The amount sent."
        ]
      },
      "label": {
        "type": "string",
        "description": [
          "The label, if given to sendpay."
        ]
      },
      "bolt11": {
        "type": "string",
        "description": [
          "The bolt11 string (if supplied)."
        ]
      },
      "bolt12": {
        "type": "string",
        "description": [
          "The bolt12 string (if supplied)."
        ]
      },
      "partid": {
        "type": "u64",
        "description": [
          "The partid (if supplied) to sendonion/sendpay."
        ]
      }
    },
    "allOf": [
      {
        "if": {
          "additionalProperties": true,
          "properties": {
            "status": {
              "type": "string",
              "enum": [
                "complete"
              ]
            }
          }
        },
        "then": {
          "additionalProperties": false,
          "required": [
            "payment_preimage"
          ],
          "properties": {
            "created_index": {},
            "id": {},
            "payment_hash": {},
            "status": {},
            "msatoshi": {},
            "amount_msat": {},
            "destination": {},
            "created_at": {},
            "groupid": {},
            "msatoshi_sent": {},
            "amount_sent_msat": {},
            "label": {},
            "bolt11": {},
            "bolt12": {},
            "partid": {},
            "updated_index": {
              "added": "v23.11",
              "type": "u64",
              "description": [
                "1-based index indicating order this payment was changed."
              ]
            },
            "payment_preimage": {
              "type": "secret",
              "description": [
                "The proof of payment: SHA256 of this **payment_hash**."
              ]
            }
          }
        }
      },
      {
        "if": {
          "additionalProperties": true,
          "properties": {
            "status": {
              "type": "string",
              "enum": [
                "pending"
              ]
            }
          }
        },
        "then": {
          "additionalProperties": false,
          "required": [],
          "properties": {
            "created_index": {},
            "id": {},
            "payment_hash": {},
            "status": {},
            "msatoshi": {},
            "amount_msat": {},
            "destination": {},
            "created_at": {},
            "groupid": {},
            "msatoshi_sent": {},
            "amount_sent_msat": {},
            "label": {},
            "bolt11": {},
            "bolt12": {},
            "partid": {},
            "message": {
              "type": "string",
              "description": [
                "Monitor status with listpays or waitsendpay."
              ]
            }
          }
        }
      }
    ]
  },
  "errors": [
    "The following error codes may occur:",
    "",
    "- 202: an parseable onion",
    "",
    "the error details are decrypted and presented here, if *shared_secrets* was provided and an error was returned by one of the intermediate nodes"
  ],
  "author": [
    "Christian Decker [decker.christian@gmail.com](mailto:decker.christian@gmail.com) is mainly responsible."
  ],
  "see_also": [
    "lightning-injectpaymentonion(7)",
    "lightning-createonion(7)",
    "lightning-sendpay(7)",
    "lightning-listsendpays(7)"
  ],
  "resources": [
    "Main web site: [https://github.com/ElementsProject/lightning](https://github.com/ElementsProject/lightning)",
    "",
    "[bolt04]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md"
  ],
  "examples": [
    {
      "request": {
        "id": "example:sendonion#1",
        "method": "sendonion",
        "params": {
          "onion": "onion10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
          "first_hop": {
            "id": "nodeid020202020202020202020202020202020202020202020202020202020202",
            "channel": "109x1x1",
            "direction": 1,
            "amount_msat": 1002,
            "delay": 21,
            "style": "tlv"
          },
          "payment_hash": "assocdata0010101010101010101010101010101010101010101010101010101"
        }
      },
      "response": {
        "message": "Monitor status with listpays or waitsendpay",
        "created_index": 10,
        "id": 10,
        "payment_hash": "assocdata0010101010101010101010101010101010101010101010101010101",
        "groupid": 1,
        "amount_sent_msat": 1002,
        "created_at": 1738000000,
        "status": "pending"
      }
    }
  ]
}
