<p>I finally got this to work. Apparently, the entire outputs array has to be passed as a string with quotes escaped. So the request on the command line would look like this:</p>
<pre><code>lightning-cli --conf=./cln.conf txprepare &quot;[{\&quot;bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\&quot;:\&quot;50000sat\&quot;}]&quot;
</code></pre>
<p>However, for  anyone else interested in sending on-chain funds from CLN, there is a single command you can use that is a lot easier. It is called <code>withdraw</code> and it is called like this:</p>
<pre><code>lightning-cli --conf=./cln.conf withdraw bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 50000
</code></pre>
<p>That command will send 50000 sats from the on-chain wallet to the address bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. There are also a few optional parameters described in the <a href="https://docs.corelightning.org/reference/lightning-withdraw" rel="nofollow noreferrer">withdraw documentation</a>.</p>

CC BY-SA 4.0
2023-10-25T18:38:36.363Z
2023-10-25T18:38:36.363Z
Zephyrus
<p>CLN 23.02.2</p>
<p>I'm trying to send an on-chain transaction from a CLN node. It requires two calls from the command line client, one to <code>txprepare</code> and the other to <code>txsend</code>. But I can't get txprepare to work.</p>
<p>The <a href="https://docs.corelightning.org/reference/lightning-txprepare" rel="nofollow noreferrer">documentation for txprepare</a> says:</p>
<pre><code>txprepare outputs [feerate] [minconf] [utxos]

The outputs is the array of output that include destination
and amount({destination: amount}). Its format is like:
[{address1: amount1}, {address2: amount2}]
or
[{address: all}].
</code></pre>
<p>How do I format the outputs parameter?</p>
<p>I tried a JSON object, like this:</p>
<pre><code>lightning-cli --conf=./cln.conf txprepare {&quot;outputs&quot;:[{&quot;bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;:&quot;50000sat&quot;}]}
</code></pre>
<p>I also tried just the array, like this:</p>
<pre><code>lightning-cli --conf=./cln.conf txprepare [{&quot;bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;:&quot;50000sat&quot;}]
</code></pre>
<p>I tried a few other formats too. In all cases, I get a response telling me my parameters are malformed.</p>
<pre><code>lightning-cli: Some parameters are malformed, cannot create a valid JSON-RPC request: { &quot;jsonrpc&quot; : &quot;2.0&quot;, &quot;method&quot; : &quot;txprepare&quot;, &quot;id&quot; : &quot;cli:txprepare#404389&quot;, &quot;params&quot; :[ [{bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:50000sat}]] }
</code></pre>

CC BY-SA 4.0
2023-10-25T17:51:01.183Z
I don’t have first-hand knowledge on the syntax of this call, but my suspicion would be that it doesn’t know what to do with the `"50000sat"`. Presumably, an amount would just be a plain number. Have you tried dropping the "sat" (and possibly the quotation marks on the number)? `lightning-cli txprepare [{"bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx":"50000sat"}]` ↦ `lightning-cli txprepare [{"bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx":50000}]`
Murch
CC BY-SA 4.0
2023-10-25T17:55:08.273Z
That gives me the same result. The documentation also says: `The amount of output is the amount to be sent from the internal wallet
(expressed, as name suggests, in amount). The string all can be used to specify
all available funds. Otherwise, it is in amount 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.`
Zephyrus
<core-lightning><sending>
How to send an on-chain transaction from CLN?
Zephyrus
# How to send an on-chain transaction from CLN?

(Asked by: username_0 on 2023-10-25)

CLN 23.02.2

I'm trying to send an on-chain transaction from a CLN node. It requires two calls from the command line client, one to `txprepare` and the other to `txsend`. But I can't get txprepare to work.

The [documentation for txprepare](https://docs.corelightning.org/reference/lightning-txprepare) says:

```
txprepare outputs [feerate] [minconf] [utxos]

The outputs is the array of output that include destination
and amount({destination: amount}). Its format is like:
[{address1: amount1}, {address2: amount2}]
or
[{address: all}].

```

How do I format the outputs parameter?

I tried a JSON object, like this:

```
lightning-cli --conf=./cln.conf txprepare {"outputs":[{"bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx":"50000sat"}]}

```

I also tried just the array, like this:

```
lightning-cli --conf=./cln.conf txprepare [{"bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx":"50000sat"}]

```

I tried a few other formats too. In all cases, I get a response telling me my parameters are malformed.

```
lightning-cli: Some parameters are malformed, cannot create a valid JSON-RPC request: { "jsonrpc" : "2.0", "method" : "txprepare", "id" : "cli:txprepare#404389", "params" :[ [{bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:50000sat}]] }

```

**Tags:** core-lightning, sending

> **Comments:**
> **username_1**: I don’t have first-hand knowledge on the syntax of this call, but my suspicion would be that it doesn’t know what to do with the `"50000sat"`. Presumably, an amount would just be a plain number. Have you tried dropping the "sat" (and possibly the quotation marks on the number)? `lightning-cli txprepare [{"bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx":"50000sat"}]` ↦ `lightning-cli txprepare [{"bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx":50000}]`  
> **username_0**: That gives me the same result. The documentation also says: `The amount of output is the amount to be sent from the internal wallet (expressed, as name suggests, in amount). The string all can be used to specify all available funds. Otherwise, it is in amount 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.`  

---

## 1 answers

### Answer by username_0 on 2023-10-25. Score: 2 | Accepted answer

I finally got this to work. Apparently, the entire outputs array has to be passed as a string with quotes escaped. So the request on the command line would look like this:

```
lightning-cli --conf=./cln.conf txprepare "[{\"bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\":\"50000sat\"}]"

```

However, for anyone else interested in sending on-chain funds from CLN, there is a single command you can use that is a lot easier. It is called `withdraw` and it is called like this:

```
lightning-cli --conf=./cln.conf withdraw bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 50000

```

That command will send 50000 sats from the on-chain wallet to the address bcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. There are also a few optional parameters described in the [withdraw documentation](https://docs.corelightning.org/reference/lightning-withdraw).


---

