Bitcoin Forum
March 09, 2026, 10:03:34 PM *
News: Latest Bitcoin Core release: 30.2 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to get the labels for the addresses when using listdescriptors false?  (Read 75 times)
takuma sato (OP)
Hero Member
*****
Offline Offline

Activity: 822
Merit: 726


View Profile
March 01, 2026, 06:31:20 PM
Last edit: March 01, 2026, 08:53:13 PM by takuma sato
Merited by vapourminer (4)
 #1

Edit: Please move this thread to the Technical Support section

So let's say you have 100's off addresses from transactions you have received and you want to create a watch-only wallet and use PSBT to move funds.

From what I've read, you must use listdescriptors (or add "false" for extra peace of mind, even tho listdescriptors without "true" does not include private addresses)

Example: I have a testnet wallet and I copy the result in green (imagine the list is way longer, like 100's of addresses):

Quote
listdescriptors false

{
  "wallet_name": "testnet3wallettest",
  "descriptors": [
    {
      "desc": "redacted",
      "timestamp": redacted,
      "active": true,
      "internal": false,
      "range": [
        0,
        1005
      ],
      "next": 6,
      "next_index": 6
    },
    {
      "desc": "redacted",
      "timestamp": redacted,
      "active": true,
      "internal": true,
      "range": [
        0,
        999
      ],
      "next": 0,
      "next_index": 0
    },
    {
      "desc": "redacted",
      "timestamp": redacted,
      "active": true,
      "internal": false,
      "range": [
        0,
        999
      ],
      "next": 0,
      "next_index": 0
    },
    {
      "desc": "redacted",
      "timestamp": redacted,
      "active": true,
      "internal": true,
      "range": [
        0,
        999
      ],
      "next": 0,
      "next_index": 0
    },
    {
      "desc": "redacted",
      "timestamp": redacted,
      "active": true,
      "internal": false,
      "range": [
        0,
        999
      ],
      "next": 0,
      "next_index": 0
    },
    {
      "desc": "redacted",
      "timestamp": redacted,
      "active": true,
      "internal": true,
      "range": [
        0,
        999
      ],
      "next": 0,
      "next_index": 0
    },
    {
      "desc": "redacted",
      "timestamp": redacted,
      "active": true,
      "internal": false,
      "range": [
        0,
        1000
      ],
      "next": 1,
      "next_index": 1
    },
    {
      "desc": "redacted",
      "timestamp": redacted,
      "active": true,
      "internal": true,
      "range": [
        0,
        999
      ],
      "next": 0,
      "next_index": 0
    }
  ]

}

Then I go to my online watch-only wallet and paste this with "importdescriptors 'thetextingreen'"

The addresses show up, however you have 100's of addresses that have no labels, so your wallet is unusable because you don't even know what you are moving.

Is there a way to get the labels all imported at once into the online wallet so you know what you are doing? I have found a script, but you have to use RPC with the jq command on linux using listlabels and getaddressesbylabel. However this seems rather cumbersome. Is it really no way to do this within the Bitcoin software? Why not just include the labels by default anyway?
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3920
Merit: 7663


Just writing some code


View Profile WWW
March 02, 2026, 03:15:35 PM
Merited by ABCbits (5), vapourminer (4), LoyceV (4), BitMaxz (1), nc50lc (1)
 #2

Labels are associated per-address, not per-descriptor, so they are not provided in listdescriptors (and generally cannot be). You will have to get the addresses with getaddressesbylabel and apply them one by one with setlabel as there is currently no bulk label adding RPC.

I have an open PR that easily creates a watchonly wallet with all of your labels, transactions, etc. but that is still under review.

takuma sato (OP)
Hero Member
*****
Offline Offline

Activity: 822
Merit: 726


View Profile
March 03, 2026, 10:30:10 PM
 #3

Labels are associated per-address, not per-descriptor, so they are not provided in listdescriptors (and generally cannot be). You will have to get the addresses with getaddressesbylabel and apply them one by one with setlabel as there is currently no bulk label adding RPC.

I have an open PR that easily creates a watchonly wallet with all of your labels, transactions, etc. but that is still under review.

That would be great. Like I said there is really no way to use the wallet without labels, if you've got a bunch of transactions, and nobody wants to do this one by one.

I've tested this script, it does the job:

Code:
CLI="./bitcoin-cli -datadir=/home/.bitcoin -rpcwallet=yourWalletFile"

$CLI listlabels | jq -r '.[]' \
| while read -r L; do
  $CLI getaddressesbylabel "$L" \
  | jq -r --arg L "$L" 'keys[] | {addr: ., label: $L} | @json'
done > labels.json

This will generate a labels.json file. Copy the file, paste it on your online node. Then run this:

Code:
CLI="./bitcoin-cli -datadir=/home/.bitcoin -rpcwallet=yourWatchOnlyWalletFile"

while read -r line; do
  addr=$(jq -r '.addr' <<<"$line")
  label=$(jq -r '.label' <<<"$line")
  $CLI setlabel "$addr" "$label" 2>/dev/null || true
done < labels.json

This will apply the labels in your watch-only wallet. Something like this couldn't have been applied by default? It does not add any complexity and seems to work fine.
takuma sato (OP)
Hero Member
*****
Offline Offline

Activity: 822
Merit: 726


View Profile
March 04, 2026, 10:50:54 PM
 #4

I just realized I see another problem:

When I used "importdescriptors" and I added the label names, there is still a problem, the fact that it all gets dumped as if you received all of these transactions at once makes the transactions not ordered by date. This is quite annoying. You would expect recent transactions to be on top and then as you scroll down you see the older transactions, this is all over the place. So im not sure what to do with this.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!