bcoin-org / bcoin

Javascript bitcoin library for node.js and browsers
https://bcoin.io
Other
3.01k stars 811 forks source link

How to merge inputs #1173

Open andriibezkorovainyi opened 12 months ago

andriibezkorovainyi commented 12 months ago

I have 1 wallet in my node, which has many accounts({ type: pubkeyhash, witness: true }). The balance is splitted among these accounts. When I need to send a bit large amount of BTC, inputs quantity can reach 400-500, with the corresponding high transaction fee. How can I merge my inputs into one? Or, maybe, there is another way to decrease fee, as it seems that bcoin hasn't added the PSBT's support yet.

andriibezkorovainyi commented 12 months ago

Hello, @joemphilips help me, please. I saw your PR with PSBT implementation, and it seems bcoin doesn't support it. I'm curious can use bitcoinjs-lib to do all signature staff and bcoin to just fetch accounts and broadcast transactions?

pinheadmz commented 12 months ago

PSBT won't help you reduce fees. If you are trying to consolidate 400-500 inputs the tx size will be very large and you can expect to pay a huge fee. Watch the mempool and wait for a low-fee period for consolidation. Another approach might be to consolidate in stages, i.e. maybe create 10-20 txs that consolidate 10-20 inputs each, and then combine those outputs if mempool fees remain low enough.

andriibezkorovainyi commented 12 months ago

@pinheadmz Thank for your response, how would you approximately rate the possible comission reduce with the second approach? I'm asking beacuse, I don't understand clear enough, what is the difference betwen one tx with 400 inputs and 20 txs with 20 txs each, in the meaning of fee's sizes. Could you explain a bit, please?

pinheadmz commented 12 months ago

Just depends on your budget and time preference. You also may hit the policy limit on tx weight if you try to add too many inputs. Here's some more links for you to browse:

Consolidation questions on stack exchange:

https://bitcoin.stackexchange.com/search?q=Consolidate

follow Murch on twitter for clues about best times to consolidate with low fee rates:

https://twitter.com/murchandamus/status/1708887501652578663