I'm running bitcoind and I want to send all my coins to another address. What is the command for this?
3 Answers
Starting with Bitcoin Core 24.0.0 you can use the sendall
RPC:
E.g.
bitcoin-cli -named sendall recipients='["<bitcoinaddress>"]' fee_rate=<sat/vB>
Note that sendall
will spend all of your UTXOs by default, including UTXOs that cannot pay for their own input weight. If you would like to maximize the funds received to the recipient address by not spending uneconomical UTXOs, use the send_max
option.
bitcoin-cli -named sendall recipients='["<bitcoinaddress>"]' fee_rate=<sat/vB> send_max=true
RPC Documentation here: https://bitcoincore.org/en/doc/24.0.0/rpc/wallet/sendall/
To be strict, OP asked to send all coins, which @michael.schuett didn't answer.
The key thing to do this is the last optional bool argument of the sendtoaddress
RPC command called subtractfeefromamount
. The way to use it is:
bitcoin-cli walletpassphrase <passphrase> <timeoutInSeconds>
bitcoin-cli sendtoaddress <bitcoinaddress> `bitcoin-cli getbalance` "" "" true
This command:
sendtoaddress <bitcoinaddress> <amount>
will do the trick.
Look at the bitcoind api for more info: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list