Search code examples
blockchainbitcoin

Can't get private keys for my bitcoin wallet on own node


I deployed bitcoin prune node on my own server and can't figure out how to get the private keys for my wallet. getwalletinfo doesn't return my wallet number, but dumpprivkey requires it:

curl --data-binary '{"jsonrpc": "1.0", "method": "getwalletinfo"}'  -H 'Content-Type: application/json' http://login:pwd@127.0.0.1:8332/
{"result":{"walletname":"takoe2","walletversion":169900,"format":"bdb","balance":0.00000000,"unconfirmed_balance":0.00000000,"immature_balance":0.00000000,"txcount":0,"keypoololdest":1690405258,"keypoolsize":1000,"hdseedid":"37acbef925f63c49a0ddf1ba118c3782a480e9c2","keypoolsize_hd_internal":1000,"paytxfee":0.00000000,"private_keys_enabled":true,"avoid_reuse":false,"scanning":false,"descriptors":false},"error":null,"id":null}

The node is working, the blocks are syncing, I can generate the new addresses for accept the payments from my website, but I worry what will happened if the server goes down forever.


Solution

  • To fetch your private keys from your own Bitcoin node, follow these two steps:

    1. Find all your Bitcoin addresses:

    Run the listaddressgroupings command. It looks like:

    curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listaddressgroupings", "params": [] }'  -H 'Content-Type: application/json' http://login:pwd@127.0.0.1:8332/
    

    This will return a list of all addresses in your wallet.

    1. Fetch private keys for each address:

    Use the dumpprivkey command with each address from the list you just obtained:

    curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "dumpprivkey", "params": ["Your_Bitcoin_Address_Here"] }'  -H 'Content-Type: application/json' http://login:pwd@127.0.0.1:8332/
    

    Replace "Your_Bitcoin_Address_Here" with each actual address. You'll get their respective private keys.

    Remember, these keys are critical - they give full control over the funds linked with their addresses. Keep them safe. If your server ever goes down, you can restore your funds using these keys. Back up your wallet regularly for extra safety.

    Update base on first comment

    To send Bitcoin from multiple addresses in one go, you can use the sendmany command. It allows you to send funds from all your wallet addresses to one or more addresses in a single transaction. Here's how:

    curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendmany", "params": ["", {"recipient_address":amount,...} ] }'  -H 'Content-Type: application/json' http://login:pwd@127.0.0.1:8332/
    

    Just replace "recipient_address" with the address you want to send to, and "amount" with the number of Bitcoins to send.

    Remember, this action can link your addresses together on the blockchain, which might affect your privacy. Also, make sure you include a sufficient transaction fee for prompt processing. Bitcoin Core usually handles this, but it's good to double-check.