Use liana-cli
Send one JSON-RPC command to a running lianad from a shell, and read the reply.
Run liana-cli against a lianad that you
started on its own.
Point liana-cli at the configuration file
liana-cli --conf /home/user/lianad.toml getinfoPass the file lianad runs on, so that liana-cli connects to the same
socket.
Start lianad gives the file each uses
without --conf.
Put --conf and --raw before the command. liana-cli sends every word
after the command to lianad as a parameter.
Define an alias for your shell session to keep commands short. The examples below use it:
alias liana-cli='liana-cli --conf /home/user/lianad.toml'A script does not use the alias, so write --conf in full there.
Pass parameters by position
Pass the parameters in the order of the parameter tables in
Call the JSON-RPC API. liana-cli reads each one
as JSON, and sends it as a string when that fails:
- Numbers and booleans: Write them bare:
2,false. - Arrays and objects: Write JSON inside single quotes, so the shell keeps
the double quotes:
'["confirmed"]'. - Txids, outpoints, addresses, PSBTs: Write them bare. They are not valid JSON, so they arrive as strings.
Write amounts in sats, and feerates as whole numbers of sat/vB.
liana-cli sends no parameter by name, so pass every parameter up to the last
one you need. To skip one, write the request yourself, as in
Pass parameters by position or by name.
Read the answer
liana-cli getnewaddress{
"result": {
"address": "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7",
"derivation_index": 14
}
}liana-cli prints the answer under result. When lianad refuses the
command, the answer sits under error instead, with a code listed in
Read an error:
{
"error": {
"code": -32602,
"message": "Invalid params: Missing 'feerate' parameter."
}
}liana-cli prints both on standard output and exits with status 0. In a
script, test the answer instead. jq -e exits with a non-zero status when
result is missing:
liana-cli --conf /home/user/lianad.toml broadcastspend "$txid" \
| jq -e .result > /dev/null || exit 1When liana-cli itself fails, it writes the reason to standard error and exits
with a non-zero status.
To get the answer of lianad in full, id and jsonrpc included, add
--raw. It prints the answer on one line, with no final newline.
Build, sign, and broadcast a spend
Build the PSBT
liana-cli createspend '{"tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx": 150000}' '[]' 2 \
| jq -r .result.psbt > spend.psbtThis pays 150,000 sats at 2 sat/vB. The empty array lets lianad pick the
coins. When the coins fall short, the answer holds missing, the sats they
lack. Then spend.psbt holds null.
Sign the PSBT
Sign spend.psbt on the signing devices of the primary path.
Store each signed copy
liana-cli updatespend "$(cat signed.psbt)"updatespend takes the PSBT in base64. Run it once per signed copy.
Broadcast the transaction
txid=$(bitcoin-cli decodepsbt "$(cat spend.psbt)" | jq -r .tx.txid)
liana-cli broadcastspend "$txid"broadcastspend takes the txid of the PSBT, which signatures do not change.
bitcoin-cli decodepsbt needs a running Bitcoin Core. On a test network, add
the network flag to bitcoin-cli, such as -signet. An empty result means
the backend accepted the transaction:
{
"result": {}
}Replace an unconfirmed transaction
Set txid to the transaction you replace, then bump its fee or cancel it:
liana-cli rbfpsbt "$txid" false 10liana-cli rbfpsbt "$txid" trueThe answer holds a new PSBT. Sign, store, and broadcast it like a spend. A
cancel takes no feerate, because lianad uses the lowest one it allows for a
replacement.
To check first whether lianad can replace the transaction, run checkrbf
Requires Liana 16.0+:
liana-cli checkrbf "$txid"It answers "replaceable": true, or false with the reason.
Sweep coins through a recovery path
You can no longer use the primary path?
Sweep to an address of another wallet. A coin sent back to this wallet waits for the full timelock again. Whoever holds a stolen primary key can spend it at once.
liana-cli createrecovery tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx 2 \
| jq -r .result.psbt > recovery.psbtThis sweeps, at 2 sat/vB, every coin that the recovery path with the shortest
timelock can spend. To use another recovery path, add its timelock in blocks as
a third parameter: 52596 for a path of about 1 year.
Sign recovery.psbt on the signing devices of that recovery path. Then store
and broadcast it as in the last two steps of the spend.
Look up coins and transactions
liana-cli listcoins '["unconfirmed","confirmed"]'liana-cli listconfirmed 1767225600 1769903999 50Dates are UNIX timestamps, in seconds.
Label a coin
liana-cli updatelabels '{"6f0e2c4a8b1d3e5f7a9c0b2d4e6f8a1c3e5b7d9f0a2c4e6b8d0f1a3c5e7b9d2f:0": "Cold storage"}'To label an address or a transaction, use the address or the txid as the key.
Filter the answer with jq
liana-cli listcoins '["confirmed"]' | jq '[.result.coins[].amount] | add // 0'{ liana-cli getinfo; liana-cli listcoins '["confirmed"]'; } \
| jq -rs '.[0].result.block_height as $tip
| .[1].result.coins | sort_by(.block_height) | .[]
| "\(.outpoint)\t\(.block_height + 52596 - $tip)"'Replace 52596 (about 1 year) with the older() value of your recovery path.
At 1 or less, the recovery path can spend the coin in the next block.
Refresh your coins well before that. Run the command
once getinfo shows sync at 1.0. Before that, the count comes out too high.
Fix a connection failure
liana-cli names the socket it tried:
Could not connect to "/home/user/.lianad/lianad_rpc": 'No such file or directory (os error 2)'| The message contains | Fix |
|---|---|
No such file or directory | No lianad has opened a socket there. Start lianad, and pass liana-cli the same --conf. |
Connection refused | lianad stopped and left its socket file behind. Start lianad again. |
Permission denied | Another user runs lianad. Run liana-cli as that user. |
Error getting config: Could not locate the configuration file. | Check the --conf path. Without --conf, the default file does not exist. |
Any other Error getting config: | liana-cli parses the file with the same code as lianad. See Fix a file lianad rejects. |