DevelopersDrive

Call the JSON-RPC API

The commands lianad answers over its Unix socket, with their parameters, responses, and errors.

Write one JSON-RPC 2.0 request per line to the socket of a lianad that you run on its own, and read one JSON object back.

Find the socket

lianad creates a Unix socket named lianad_rpc in its data directory, with mode 0600 (read and write for its owner only). Connect as the user that runs lianad.

ConfigurationSocket path
Neither data directory key, on Linux~/.liana/<network>/lianad_rpc
Neither data directory key, on macOS~/Library/Application Support/Liana/<network>/lianad_rpc
data_directory = "<dir>"<dir>/lianad_rpc
data_dir = "<dir>"<dir>/<network>/lianad_rpc

<network> is the network value of [bitcoin_config]: bitcoin, testnet, testnet4, signet, or regtest. See Set the data directory.

Want to drive a wallet you use in Liana?

Start lianad on its daemon.toml first, as Attach Liana to a running lianad describes.

Send a request

A request is a JSON object on one line, ending with \n:

  • jsonrpc: Required. Send "2.0".
  • id: Required. An unsigned integer or a string. lianad echoes it back.
  • method: Required. The command name.
  • params: Optional. An array, by position, or an object, by name.
Request
{"jsonrpc": "2.0", "id": 1, "method": "getnewaddress", "params": []}
Response
{"jsonrpc":"2.0","result":{"address":"bc1q…","derivation_index":13},"id":1}

The response carries result or error and ends with no newline. Either read until the bytes parse as one JSON object, or shut down your side of the connection after the request and read until lianad closes it:

rpc.py
import json, os, socket

# On macOS: "~/Library/Application Support/Liana/bitcoin/lianad_rpc"
SOCKET = os.path.expanduser("~/.liana/bitcoin/lianad_rpc")

def call(method, params=None):
    request = {"jsonrpc": "2.0", "id": 1, "method": method, "params": params or []}
    with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
        sock.connect(SOCKET)
        sock.sendall(json.dumps(request).encode() + b"\n")
        sock.shutdown(socket.SHUT_WR)  # lianad answers, then closes
        data = b""
        while chunk := sock.recv(65536):
            data += chunk
    response = json.loads(data)
    if "error" in response:
        raise RuntimeError(response["error"])
    return response["result"]

print(call("getinfo")["block_height"])

One connection can carry several requests, which lianad answers in order.

Pass parameters by position or by name

The parameter tables below list parameters in positional order. To leave out an optional parameter that comes before one you need, pass an object:

{"jsonrpc": "2.0", "id": 2, "method": "updatederivationindexes", "params": {"change": 40}}

To skip a parameter, leave it out.

Read an error

Error response
{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params: Missing 'txid' parameter."},"id":3}
codeWhen
-32601The method does not exist. The message is Method not found.
-32602A parameter is missing or malformed. The message then starts with Invalid params:. lianad also returns this code when it refuses the command: unknown or spent coin, feerate out of range, address for another network, missing signatures, and every other wallet-level refusal.
-32603lianad could not start a rescan.
1000The backend refused to broadcast the transaction. The message carries its reason.

When the coins cannot pay for a spend, createspend and rbfpsbt return a result with a missing field, not an error.

Check and stop lianad

getinfo

No parameters. Returns:

Prop

Type

Result
{
  "block_height": 961200,
  "change_index": 4,
  "descriptors": {
    "main": {
      "change_desc": "wsh(or_d(pk([aabbccdd]xpub68JJ…/1/*),and_v(v:pkh([aabbccdd]xpub68JJ…/1/*),older(10000))))#sqk8au7v",
      "multi_desc": "wsh(or_d(pk([aabbccdd]xpub68JJ…/<0;1>/*),and_v(v:pkh([aabbccdd]xpub68JJ…/<0;1>/*),older(10000))))#38v445qv",
      "receive_desc": "wsh(or_d(pk([aabbccdd]xpub68JJ…/0/*),and_v(v:pkh([aabbccdd]xpub68JJ…/0/*),older(10000))))#wx6v3mks"
    }
  },
  "last_poll_timestamp": 1790000000,
  "network": "bitcoin",
  "receive_index": 13,
  "rescan_progress": null,
  "sync": 1.0,
  "timestamp": 1767225600,
  "version": "16.0"
}

stop

No parameters. lianad answers {}, then shuts down.

Generate and list addresses

getnewaddress

No parameters. Derives the receive address at the next index and moves receive_index to it, even if the previous address never received anything. Returns address (string) and derivation_index (integer).

listrevealedaddresses

Lists the addresses up to the last revealed index, in descending index order.

Prop

Type

Returns continue_from, the start_index of the next page (null when no index is left), and addresses, an array of:

Prop

Type

listaddresses

Derives receive and change addresses by index, without moving receive_index or change_index.

Prop

Type

Returns addresses, an array of index (integer), receive (string), and change (string).

updatederivationindexes

Moves receive_index, change_index, or both, forward. Pass at least one.

Prop

Type

lianad ignores an index lower than the current one. It moves each index by at most 1,000 per call, and stops there without an error. Returns receive and change, the indexes after the call. Call it again until they reach your target.

List coins

listcoins

Lists the wallet's coins. With both filters, a coin must match both.

Prop

Type

StatusThe coin
unconfirmedIs not in a block yet, and no transaction spends it.
confirmedIs in a block, and no transaction spends it.
spendingIs spent by an unconfirmed transaction.
spentIs spent by a confirmed transaction.

Returns coins, an array of:

Prop

Type

Read a default label

Requires Liana 16.0+

listcoins, listconfirmed and listtransactions give each coin and transaction a default_label. It is the string "none", or an object with one key, which says where the label comes from:

  • payment: The label of the transaction's single payment.
  • transaction: The label of the transaction that created this change.
  • address: The label of the address that received the payment.
  • funding: The label shown on the coins this coin was moved from.

A transaction's default_label is "none" or address. The other keys appear on coins. For a transaction with a single payment, Liana shows the label of that payment, which getlabels returns.

{"default_label": {"address": "Salary"}}

The item's own label is not in default_label. Ask getlabels for it. Labels lists which item gives which default.

Build, sign, and broadcast a spend

createspend builds a PSBT. lianad never signs. Sign the PSBT with your signing devices, store each signed copy with updatespend, then call broadcastspend.

createspend

Builds a spend PSBT. It does not store it.

Leave change_address out unless you sweep

lianad sends everything left after the destinations and the fee to change_address. Without it, the change goes to the wallet's next change address. Pass an address you do not control, and you lose that bitcoin.

To sweep the wallet to another one, list every coin in outpoints and pass the destination as change_address. lianad creates that output only when enough is left after the other destinations and the fee. Otherwise it adds the remainder to the fee, without an error.

Prop

Type

Returns psbt, the PSBT in base64, and warnings, an array of strings. When the coins cannot pay for the transaction, it returns missing instead: the sats still needed.

Request
{"jsonrpc": "2.0", "id": 4, "method": "createspend", "params": {"destinations": {"bc1q…": 150000}, "outpoints": [], "feerate": 5}}
Result
{"psbt": "cHNidP8BA…", "warnings": []}
Result when the coins fall short
{"missing": 42310}

lianad refuses:

  • An output under 500 sats.
  • A fee over 1 BTC, or a feerate over 1,000 sat/vB.
  • A coin in outpoints that is unknown, spending, spent, or immature.
  • An address for another network.

lianad adds a change output only when it is worth its cost, and never under 500 sats. Otherwise it adds the leftover to the fee. When the leftover is larger than the cost of adding a change output, a warning says so. Another warning reports extra fee paid for unconfirmed parent transactions.

updatespend

Stores a PSBT. Returns {}.

Prop

Type

For a new transaction, every input must be a coin of the wallet. For a transaction lianad already stores, it keeps its copy and adds the new signatures of each input to it. Store the copy from each signing device, in any order.

listspendtxs

Lists the stored PSBTs.

Prop

Type

Returns spend_txs, an array of:

Prop

Type

broadcastspend

Finalizes a stored PSBT and broadcasts it through the backend. Returns {} once lianad has polled the backend again.

Prop

Type

A PSBT without enough signatures fails with -32602. A transaction the backend refuses fails with 1000. The PSBT stays stored either way.

delspendtx

Deletes a stored PSBT and the signatures collected on it. It does not touch a transaction already broadcast. Returns {}, even for an unknown txid.

Prop

Type

rbfpsbt

Builds a PSBT that replaces an unconfirmed transaction spending coins of the wallet, or a stored PSBT. It does not store it. Returns the same fields as createspend.

Prop

Type

is_cancelThe replacement
trueKeeps at least one input of the original, and pays everything to one change output.
falseKeeps every input and every non-change output. Only the change output can differ.

Both modes can add confirmed coins to pay the higher fee. The lowest feerate allowed is the highest feerate among the mempool transactions it replaces, rounded down to a whole sat/vB, plus 1 sat/vB. With none in the mempool, it is 1 sat/vB. A lower feerate fails. The message states the minimum. The call also fails when the original does not signal replace-by-fee.

From Liana 16.0, lianad looks for the original among the wallet's unconfirmed spends first, then among the stored PSBTs. A stored PSBT must then be fully signed. lianad also refuses an original that does not verifiably spend coins of the wallet. Each input must carry valid signatures that commit to the whole transaction (SIGHASH_ALL). The call then fails with Refusing to replace a transaction which does not verifiably spend our coins.

checkrbf

Requires Liana 16.0+

Tells whether rbfpsbt can replace a transaction, without building the replacement. It runs the checks of rbfpsbt on the original: lianad must find it, a stored PSBT must be fully signed, and it must verifiably spend coins of the wallet. It does not check replace-by-fee signaling, the feerate, or whether the coins can pay a higher fee.

Prop

Type

Returns replaceable, a boolean, and reason, the message of the check that failed, or null when rbfpsbt can replace the transaction.

Result
{"replaceable": true, "reason": null}

Sweep coins through a recovery path

createrecovery

Builds a PSBT that sends coins through a recovery path to one address. It does not store it. Returns psbt, the PSBT in base64. From Liana 16.0, it also returns warnings, an array.

Prop

Type

A timelock counts from the block of each coin. lianad counts a coin as recoverable when the next block could include the recovery:

tip_height + 1 >= coin.block_height + timelock

tip_height is the height of the backend's chain tip, which getinfo reports as block_height once the wallet is synced.

With outpoints, a coin that is unknown, already spent, or not yet spendable through the path fails the whole call. With no coin to spend, the call fails with No coin currently spendable through this timelocked recovery path. When the coins cannot pay the fee plus an output of 500 sats or more that is worth its cost, the call fails with -32602. createspend would return missing instead.

warnings holds to_own_address when address belongs to this wallet Requires Liana 16.0+. The coins would then stay under the same descriptor, with a timelock that restarts for each of them. If you can no longer spend with the primary path, send them to an address of another wallet.

Rescan and read the history

startrescan

Starts a rescan of the blockchain from a date. Returns {}. Follow it with rescan_progress in getinfo.

Prop

Type

It fails while another rescan runs. With a pruned Bitcoin Core, a date before the pruned blocks fails with -32603 (see what pruning costs you). With an Electrum server, lianad scans the whole history of the wallet's addresses, whatever the date.

listconfirmed

Lists the wallet's transactions whose block time falls between two dates.

Prop

Type

Returns transactions, an array of:

Prop

Type

The order of the array is not guaranteed. Sort it by time.

listtransactions

Returns the wallet's transactions with the given txids, in the same transactions shape as listconfirmed. A txid that does not touch the wallet is absent from the result.

Prop

Type

Label addresses, transactions, and coins

A label belongs to an address of the wallet's network, a txid, or an outpoint.

updatelabels

Sets or deletes labels. Returns {}.

Prop

Type

After each call, lianad computes the default labels of the whole wallet again Requires Liana 16.0+.

Request
{"jsonrpc": "2.0", "id": 5, "method": "updatelabels", "params": {"labels": {"bc1q…": "Savings", "4d3c…:0": null}}}

getlabels

Returns labels, an object of item to label. An item with no label is absent.

Prop

Type

getlabelsbip329

Exports labels in the BIP 329 format, in the order lianad first stored them.

Prop

Type

Returns labels, an array of records with type (addr, tx, or output), ref, and label. Raise offset by limit until a page comes back shorter than limit.

Next steps