{
  "$schema": "../rpc-schema-draft.json",
  "type": "object",
  "rpc": "fundchannel",
  "title": "Command for establishing a lightning channel",
  "description": [
    "The **fundchannel** RPC command opens a payment channel with a peer by committing a funding transaction to the blockchain as defined in BOLT #2.",
    "",
    "If not already connected, **fundchannel** will automatically attempt to connect if Core Lightning knows a way to contact the node (either from normal gossip, or from a previous **connect** call).",
    "",
    "This auto-connection can fail if Core Lightning does not know how to contact the target node; see lightning-connect(7).",
    "",
    "Once the transaction is confirmed, normal channel operations may begin. Readiness is indicated by **listpeers** reporting a *state* of `CHANNELD_NORMAL` for the channel."
  ],
  "request": {
    "required": [
      "id",
      "amount"
    ],
    "additionalProperties": false,
    "properties": {
      "id": {
        "type": "pubkey",
        "description": [
          "Id is the peer id obtained from connect."
        ]
      },
      "amount": {
        "type": "sat_or_all",
        "description": [
          "The amount in satoshis taken from the internal wallet to fund the channel (but if we have any anchor channels, this will always leave at least `min-emergency- msat` as change). The string *all* can be used to specify all available funds (may be restricted by the `utxos` parameter, and limited to 16777215 satoshi if large channels were not negotiated with the peer). Otherwise, it is in satoshi precision; it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*. The value cannot be less than the dust limit, currently set to 546, nor more than 16777215 satoshi (unless large channels were negotiated with the peer)."
        ]
      },
      "feerate": {
        "type": "feerate",
        "description": [
          "Used for the opening transaction and (unless *option_anchors* is negotiated), as initial feerate for commitment and HTLC transactions (see NOTES in lightning-feerates(7))."
        ],
        "default": "*normal*"
      },
      "announce": {
        "type": "boolean",
        "description": [
          "Whether to announce this channel or not. An unannounced channel is considered private."
        ],
        "default": "True"
      },
      "minconf": {
        "type": "u32",
        "description": [
          "The minimum number of confirmations that used outputs should have."
        ],
        "default": "1"
      },
      "push_msat": {
        "type": "msat",
        "description": [
          "The amount of millisatoshis to push to the channel peer at open. Note that this is a gift to the peer -- these satoshis are added to the initial balance of the peer at channel start and are largely unrecoverable once pushed."
        ]
      },
      "close_to": {
        "type": "string",
        "description": [
          "A Bitcoin address to which the channel funds should be sent to on close. Only valid if both peers have negotiated `option_upfront_shutdown_script`. Returns `close_to` set to closing script iff is negotiated."
        ]
      },
      "request_amt": {
        "type": "sat",
        "description": [
          "An amount of liquidity you'd like to lease from the peer. If peer supports `option_will_fund`, indicates to them to include this much liquidity into the channel. Must also pass in *compact_lease*."
        ]
      },
      "compact_lease": {
        "type": "string",
        "description": [
          "A compact representation of the peer's expected channel lease terms. If the peer's terms don't match this set, we will fail to open the channel."
        ]
      },
      "utxos": {
        "type": "array",
        "description": [
          "The utxos to be used to fund the channel, as an array of `txid:vout`."
        ],
        "items": {
          "type": "outpoint"
        }
      },
      "mindepth": {
        "description": [
          "Number of confirmations required before we consider the channel active."
        ],
        "type": "u32"
      },
      "reserve": {
        "type": "sat",
        "description": [
          "The amount we want the peer to maintain on its side of the channel. It can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*."
        ],
        "default": "1% of the funding amount"
      },
      "channel_type": {
        "added": "v24.02",
        "type": "array",
        "items": {
          "type": "u32",
          "description": [
            "Represents the explicit channel type to request. There is currently no sanity checking on this value so if you use strange values and your channel breaks, you get to keep both pieces. BOLT 2 defines the following value types:",
            "```",
            "The currently defined basic types are:",
            "  - `option_static_remotekey` (bit 12).",
            "  - `option_anchors` and `option_static_remotekey` (bits 22 and 12).",
            "",
            "Each basic type has the following variations allowed:",
            "  - `option_scid_alias` (bit 46).",
            "  - `option_zeroconf` (bit 50).",
            "```"
          ]
        }
      }
    }
  },
  "response": {
    "required": [
      "tx",
      "txid",
      "outnum",
      "channel_type",
      "channel_id"
    ],
    "additionalProperties": false,
    "properties": {
      "tx": {
        "type": "hex",
        "description": [
          "The raw transaction which funded the channel."
        ]
      },
      "txid": {
        "type": "txid",
        "description": [
          "The txid of the transaction which funded the channel."
        ]
      },
      "outnum": {
        "type": "u32",
        "description": [
          "The 0-based output index showing which output funded the channel."
        ]
      },
      "channel_id": {
        "type": "hash",
        "description": [
          "The channel_id of the resulting channel."
        ]
      },
      "channel_type": {
        "type": "object",
        "description": [
          "Channel_type as negotiated with peer."
        ],
        "added": "v24.02",
        "additionalProperties": false,
        "required": [
          "bits",
          "names"
        ],
        "properties": {
          "bits": {
            "type": "array",
            "description": [
              "Each bit set in this channel_type."
            ],
            "added": "v24.02",
            "items": {
              "type": "u32",
              "description": [
                "Bit number."
              ]
            }
          },
          "names": {
            "type": "array",
            "description": [
              "Feature name for each bit set in this channel_type. Note that *anchors_zero_fee_htlc_tx* is a deprecated synonym for *anchors*."
            ],
            "added": "v24.02",
            "items": {
              "type": "string",
              "enum": [
                "static_remotekey/even",
                "anchor_outputs/even",
                "anchors_zero_fee_htlc_tx/even",
                "anchors/even",
                "scid_alias/even",
                "zeroconf/even"
              ],
              "description": [
                "Name of feature bit."
              ]
            }
          }
        }
      },
      "close_to": {
        "type": "hex",
        "description": [
          "The raw scriptPubkey which mutual close will go to; only present if *close_to* parameter was specified and peer supports `option_upfront_shutdown_script`."
        ]
      },
      "mindepth": {
        "type": "u32",
        "description": [
          "Number of confirmations before we consider the channel active."
        ]
      }
    }
  },
  "errors": [
    "The following error codes may occur:",
    "",
    "- -1: Catchall nonspecific error.",
    "- 300: The maximum allowed funding amount is exceeded.",
    "- 301: There are not enough funds in the internal wallet (including fees) to create the transaction.",
    "- 302: The output amount is too small, and would be considered dust.",
    "- 303: Broadcasting of the funding transaction failed, the internal call to bitcoin-cli returned with an error.",
    "- 313: The `min-emergency-msat` reserve not be preserved (and we have or are opening anchor channels).",
    "",
    "Failure may also occur if **lightningd** and the peer cannot agree on channel parameters (funding limits, channel reserves, fees, etc.)."
  ],
  "see_also": [
    "lightning-connect(7)",
    "lightning-listfunds()",
    "lightning-listpeers(7)",
    "lightning-feerates(7)",
    "lightning-multifundchannel(7)"
  ],
  "resources": [
    "Main web site: [https://github.com/ElementsProject/lightning](https://github.com/ElementsProject/lightning)"
  ],
  "examples": [
    {
      "request": {
        "id": "example:fundchannel#1",
        "method": "fundchannel",
        "params": {
          "id": "nodeid050505050505050505050505050505050505050505050505050505050505",
          "amount": 1000000,
          "announce": true
        }
      },
      "response": {
        "tx": "020000000000305fundchanneltx350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000350003500035000",
        "txid": "channeltxid350000350000350000350000350000350000350000350000350000",
        "channel_id": "channelid0350000350000350000350000350000350000350000350000350000",
        "channel_type": {
          "bits": [
            12,
            22
          ],
          "names": [
            "static_remotekey/even",
            "anchors/even"
          ]
        },
        "outnum": 1
      }
    },
    {
      "description": [
        "This example shows how to to open new channel with peer 1 from one whole utxo (you can use **listfunds** command to get txid and vout):"
      ],
      "request": {
        "id": "example:fundchannel#2",
        "method": "fundchannel",
        "params": {
          "id": "nodeid010101010101010101010101010101010101010101010101010101010101",
          "amount": "all",
          "feerate": "normal",
          "push_msat": 100000,
          "utxos": [
            "channeltxid350000350000350000350000350000350000350000350000350000:1"
          ]
        }
      },
      "response": {
        "tx": "020000000000401fundchanneltx410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000410004100041000",
        "txid": "channeltxid410000410000410000410000410000410000410000410000410000",
        "channel_id": "channelid0410000410000410000410000410000410000410000410000410000",
        "channel_type": {
          "bits": [
            12,
            22
          ],
          "names": [
            "static_remotekey/even",
            "anchors/even"
          ]
        },
        "outnum": 1
      }
    }
  ]
}
