BlockchainCommons / Learning-Bitcoin-from-the-Command-Line

A complete course for learning Bitcoin programming and usage from the command
3.12k stars 754 forks source link

curl creating of legacy address doesn't work #537

Closed zerotobtc closed 2 years ago

zerotobtc commented 2 years ago

Hello folks,

I'm currently inthe interlude about using curl. But I can't get the legacy address. I entered ""and "legacy" as parameters like this:

curl --user StandUp --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getrawchangeaddress", "params": ["", "legacy"] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ | jq -r '.'

but I get the following error:

  "error": {
    "code": -1,
    "message": "getrawchangeaddress ( \"address_type\" )\n\nReturns a new Bitcoin address, for receiving change.\nThis is for use with raw transactions, NOT normal use.\n\nArguments:\n1. address_type    (string, optional, default=set by -changetype) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\".\n\nResult:\n\"str\"    (string) The address\n\nExamples:\n> bitcoin-cli getrawchangeaddress \n> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", \"method\": \"getrawchangeaddress\", \"params\": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n"
  },
  "id": "curltest"
}

However, if I try it with only ""as argument it fails. Using only "legacy" seems to give me the right address type ("mfzDenj..."), running it without any arguments seems to give me the fallback to Bech32 ("tb1...").

But in the repo it says that using ONLY "legacy" would give me back a Bech32 ??

Thanks for help in advance!

shannona commented 2 years ago

You're correct. It looks like the first parameter was dropped at some point, so just including the address-type is now right.

shannona commented 2 years ago

Turns out the problem was a discrepancy between getnewaddress and the newer getrawchangeaddress. The first takes an extra argument for label, and the second. It's been resolved & tested. Thank you!