Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: s2 on March 01, 2017, 10:14:33 AM



Title: How do you transfer all the funds in a bitcoind wallet via RPC?
Post by: s2 on March 01, 2017, 10:14:33 AM
I'm curious what the RPC approach is to transfer all the funds in a wallet to an external address but with a reasonable transaction fee?

(This is version 0.13.1 if that matters)

E.g. If I have 20,000,000 satoshi balance in the bitcoind controlled wallet and want to transfer as much as possible to a new address but with sufficient fees it's likely to be in the next block, what do I provide to sendToAddress?



Title: Re: How do you transfer all the funds in a bitcoind wallet via RPC?
Post by: achow101 on March 01, 2017, 02:10:22 PM
Run
Code:
estimatefee <blocks>
where <blocks> is the number of blocks that you want your transaction to be confirmed within. Note that you cannot choose 1 because that is too soon and not enough data can be gathered for 1 block. I recommend using 3.

Take the result of the estimatefee command above and run
Code:
settxfee <fee>
where <fee> is the output of the estimatefee command.

Then whenever you send using the wallet RPCs in the same session, it will use the fees set by settxfee.


Title: Re: How do you transfer all the funds in a bitcoind wallet via RPC?
Post by: s2 on March 01, 2017, 06:01:05 PM
Many thanks for the reply, I have changed it as you've said and so far so good.


Do you know what happens if you construct a transaction which used loads of inputs therefore requiring a larger fee?

(Also has it already been discussed changing the RPC methods to just use satoshis?  Having it return floating point bitcoin has already flagged one rounding problem today :) )


Title: Re: How do you transfer all the funds in a bitcoind wallet via RPC?
Post by: achow101 on March 01, 2017, 06:07:31 PM
Many thanks for the reply, I have changed it as you've said and so far so good.


Do you know what happens if you construct a transaction which used loads of inputs therefore requiring a larger fee?
The fee returned by estimatefee and the fee entered into settxfee is actually the fee rate in BTC/kB. So if you have a large transaction, it will pay a higher fee which is still using the fee rate specified in settxfee.

(Also has it already been discussed changing the RPC methods to just use satoshis?  Having it return floating point bitcoin has already flagged one rounding problem today :) )
There is discussion about making it all in satoshis instead of BTC. See  https://github.com/bitcoin/bitcoin/pull/9855 and https://github.com/bitcoin/bitcoin/pull/9882