bitcoin / bitcoin

Bitcoin Core integration/staging tree
https://bitcoincore.org/en/download
MIT License
77.76k stars 35.81k forks source link

importaddress failed, Only legacy wallets are supported by this command. #29772

Open ray2cycle opened 5 months ago

ray2cycle commented 5 months ago

Is there an existing issue for this?

Current behaviour

I want to import the address or public key into bitcoind because I want to list the unspent utxo based on my bitcoind node and then assemble the transaction on the client side. However, an error will be reported when importing the address and public key.

Error:

error code: -4
error message:
Only legacy wallets are supported by this command

Expected behaviour

success and list unspent utxo success.

Steps to reproduce

bitcoin-cli importaddress mk4xz7tbbQDcQY68qYehydV9PRBWdVGNw1 "ray"

error code: -4
error message:
Only legacy wallets are supported by this command

bitcoin-cli importpubkey 03f3de8f736a0bff7dfe446138acf98c23199c0710c704416dc9b6338bf37900e9 "ray_pub" true

error code: -4
error message:
Only legacy wallets are supported by this command

bitcoind start cmd: bitcoind -blocksonly=false -wallet=ray -addresstype=legacy

Relevant log output

No response

How did you obtain Bitcoin Core

Pre-built binaries

What version of Bitcoin Core are you using?

Bitcoin Core version v25.0.0

Operating system and version

Ubuntu 22.04.3 LTS

Machine specifications

No response

1440000bytes commented 5 months ago

This should work for a descriptor wallet with disable_private_keys=true:

$ bitcoin-cli importdescriptors '[{ "desc": "addr(mk4xz7tbbQDcQY68qYehydV9PRBWdVGNw1)#CHECKSUM", "timestamp":"now", "label": "ray"}]'

You will get the CHECKSUM with getdescriptorinfo "addr(mk4xz7tbbQDcQY68qYehydV9PRBWdVGNw1)"

maflcko commented 5 months ago

I guess the error message could be adjusted to say that the RPC has been replaced by another one for descriptor wallets.

laanwj commented 4 months ago

Yes, adding an example would be useful.

RichardGantz commented 2 months ago

I have a bitcoincore v27.0.0 running on a "Raspberry Pi OS with desktop, Release date: March 15th 2024.System: 64-bit,Kernel version: 6.6, Debian version: 12 (bookworm)" over the tor network, which is fully synchronized.

I installed a "Electrum Personal Server v0.2.4, but it does not start because of this same JsonRpcError ("code = -4; message = "Only legacy wallets are supported by this command"). Up to this point I tried several zpubs and addresses, but they were all native segwit P2WPKH.

Then I created a 'Base58 (legacy)' address within gthe "Receive" tab of the bitcoincore default wallet, i created and this address begins with a 1 and therefore is really a legacy address, right?

The JsonRpcError which interrupts the startup of the EPS then changed to:

{'code': -5, 'message': 'Invalid or unsupported Segwit (Bech32) or Base58 encoding.'}

Is there a legacy address you have that would be accepted by bitcoincore when given via JsonRpc?

sipa commented 2 months ago

The terminology is confusing, but "legacy wallets" and "legacy addresses" have nothing to do with one another:

What you've done is created a legacy address in a descriptor wallet (which is supported). The issue is that descriptor wallet do not support the importaddress RPC (though that may change, see #30175). The solution (for now) is to create a legacy wallet in Bitcoin Core instead of a descriptor wallet, and let EPS use that. Longer term, I assume EPS will have to be adapted to use the descriptor wallet RPCs (like importdescriptor).

RichardGantz commented 2 months ago

Dear sipa,

thank you so much for your quick and crystal clear answer. The EPS started up successfully after I created the legacy wallet.

Please allow me to add for newbees like me that

  1. I had to stop bitcoin-core and start it once with the additional parameter -deprecatedrpc=create_bdb.
  2. After that started up I was able to create the legacy wallet with the following command in the console window: createwallet "LegacyWallet" false false "" false false.

Shutdown of bitcoin-core and restart without the additional parameter still could open the "LegacyWallet" with the hint that these kinds of wallets will not be supported one day in the near future.

But EPS could import all zpubs and seqwit addresses and started up successful.

THANK YOU VERY MUCH!

maflcko commented 2 months ago

Not sure what to do here, other than possibly adjusting the error message https://github.com/bitcoin/bitcoin/issues/29772#issuecomment-2029810953 or closing this as a duplicate of https://github.com/bitcoin/bitcoin/issues/30175