@@ -258,6 +258,44 @@ $ bitcoin-cli decodepsbt cHNidP8BAJoCAAAAAkiMdlxF3M20VpdnCMK0NOkEoETG6Aa4HpC8V
258258}
259259```
260260
261+ In newer versions of ` lnd ` (` v0.18.0-beta ` and later), there is also the new
262+ ` lncli wallet psbt fundtemplate ` command that offers a few advantages over the
263+ previous ` lncli wallet psbt fund ` command:
264+ 1 . The ` fundtemplate ` sub command allows users to specify only some inputs, even
265+ if they aren't enough to pay for all the outputs. ` lnd ` will then select more
266+ inputs and calculate the change amount and fee correctly (whereas the ` fund `
267+ command would return an error, complaining about not enough inputs being
268+ specified).
269+ 2 . The ` fundtemplate ` sub command allows users to specify that an existing
270+ output should be used for any left-over change after selecting coins.
271+
272+ Here's the above example with the new sub command, where we only specify one
273+ input:
274+
275+ ``` shell
276+ $ LOCK_ID=$( cat /dev/urandom | head -c32 | xxd -p -c999)
277+ $ lncli wallet leaseoutput --outpoint 3597b451ff56bc901eb806e8c644a004e934b4c208679756b4cddc455c768c48:1 \
278+ --lockid $LOCK_ID --expiry 600
279+ $ lncli wallet psbt fundtemplate --outputs=' ["bcrt1qjrdns4f5zwkv29ln86plqzs092yd5fg6nsz8re:50000000"]' \
280+ --inputs=' ["3597b451ff56bc901eb806e8c644a004e934b4c208679756b4cddc455c768c48:1"]'
281+ {
282+ " psbt" : " cHNidP8BAJoCAAAAAkiMdlxF3M20VpdnCMK0NOkEoETG6Aa4HpC8Vv9RtJc1AQAAAAAAAAAA4lBjZUtG260qBBgVRqMQqmMV+XRTKubrHbc66YOl7/gBAAAAAAAAAAACgPD6AgAAAAAWABSQ2zhVNBOsxRfzPoPwCg8qiNolGtIkCAcAAAAAFgAUuvRP5r7qAvj0egDxyX9/FH+vukgAAAAAAAEA3gIAAAAAAQEr9IZcho/gV/6fH8C8P+yhNRZP+l3YuxsyatdYcS0S6AEAAAAA/v///wLI/8+yAAAAABYAFDXoRFwgXNO5VVtVq2WpaENh6blAAOH1BQAAAAAWABTcAR0NeNdDHb96kMnH5EVUcr1YwwJHMEQCIDqugtYLp4ebJAZvOdieshLi1lLuPl2tHQG4jM4ybwEGAiBeMpCkbHBmzYvljxb1JBQyVAMuoco0xIfi+5OQdHuXaAEhAnH96NhTW09X0npE983YBsHUoMPI4U4xBtHenpZVTEqpVwAAAAEBHwDh9QUAAAAAFgAU3AEdDXjXQx2/epDJx+RFVHK9WMMBAwQBAAAAAAEA6wIAAAAAAQFvGpeAR/0OXNyqo0zrXSzmkvVfbnytrr4onbZ61vscBwEAAAAAAAAAAAIAJPQAAAAAACIAILtTVbSIkaFDqjsJ7EOHmTfpXq/fbnrGkD3/GYHYHJtMVl0NBAAAAAAWABQqnZOHOGzDIzZAeXK+YwHq1AHtXQJIMEUCIQDgx3xEhlioV1Q+yAPKiaXMwkv1snoejbckZOKFe0R6WAIgB41dEvK3zxI665YVWfcih0IThTkPoOiMgd6xGaKQXbwBIQMdgXMwQDF+Z+r3x5JKdm1TBvXDuYC0cbrnLyqJEU2ciQAAAAABAR9WXQ0EAAAAABYAFCqdk4c4bMMjNkB5cr5jAerUAe1dAQMEAQAAAAAAAA==" ,
283+ " change_output_index" : 1,
284+ " locks" : [
285+ {
286+ " id" : " ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98" ,
287+ " outpoint" : " f8efa583e93ab71debe62a5374f91563aa10a3461518042aaddb464b656350e2:1" ,
288+ " expiration" : 1601560626
289+ }
290+ ]
291+ }
292+ ```
293+
294+ Note that the format of the ` --outputs ` parameter is slightly different from the
295+ one in ` lncli wallet psbt fund ` . The order of the outputs is important in the
296+ template, so the new command uses an array notation, where the old command used
297+ a map (which doesn't guarantee preservation of the order of the elements).
298+
261299## Signing and finalizing a PSBT
262300
263301Assuming we now want to sign the transaction that we created in the previous
0 commit comments