0

I have tried with the commands below

sendtoaddress <address> `bitcoin-cli getbalance` "" "" true
sendtoaddress <address> "bitcoin-cli getbalance" "" "" true
sendtoaddress <address> bitcoin-cli getbalance "" "" true
sendtoaddress <address> getbalance "" "" true
sendtoaddress <address> *.* "" "" true

But none worked

error: Error parsing JSON:
1
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    May 18 at 10:44

1 Answer 1

1

It sounds like you want to send all wallet funds in a single-line command.

In a Unix shell, this should work:

bitcoin-cli sendtoaddress <address> $(bitcoin-cli getbalance) "" "" true

The Windows command prompt doesn't support the substitution via backticks or $(…), but I'm reading that you should be able to use a FOR /F loop with the usebackq option to emulate it:

for /F "usebackq delims=" %A in (`bitcoin-cli getbalance`) do bitcoin-cli sendtoaddress <address> %A "" "" true

I have no Windows machine and have not tested this, I suggest you verify carefully and use at own risk.

Starting with the next release, Bitcoin Core v24, you will be able to use sendall:

bitcoin-cli sendall '["<address>"]' null "unset" <feerate (s/vB)>
4
  • i have tried your command on v0.21.1. bitcoin-cli sendtoaddress <address> $(bitcoin-cli getbalance) "" "" true but none worked error: Error parsing JSON: $(bitcoin-cli
    – kng
    May 19 at 1:36
  • What shell are you using?
    – Murch
    May 19 at 4:55
  • i am running Command Prompt from bat file
    – kng
    May 19 at 5:45
  • That explains it! I've amended my suggestion. I don't use Windows, it's not tested, please verify carefully, use at own risk
    – Murch
    May 19 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.