Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtracting fee from output amount #41

Open
vladanm opened this issue May 21, 2019 · 2 comments
Open

Subtracting fee from output amount #41

vladanm opened this issue May 21, 2019 · 2 comments

Comments

@vladanm
Copy link

vladanm commented May 21, 2019

Hi, i mostly having a problem when i want to send "max amount from address"

Inputs from coinselect are always undefined because the fee is calculated on top of the target amount, and then I don't have enough satoshi in inputs to send "max target amount + fee"

To give an example, we have 100,000 satoshi on address, and we want to send all, so in target value we set 100,000 sat. and feerate 100 sat.
Fee is then calculated to be 24,000 sat, and by coinselect algorithm, i need 124,000 sat on the address to send 100,000.

What we need is that coinselect return output value of 76,000 and fee of 24,000. So when Transaction is built, 100% of satoshi is used, leaving an address with 0 balance.

Is this possible to do using coin select, or we need some kind of workaround for this

Thank you.

@ac0uk
Copy link

ac0uk commented Apr 10, 2020

Pro-tip: if you want to send-all inputs to an output address, coinselect/split with a partial output (.address defined, no .value) can be used to send-all, while leaving an appropriate amount for the fee.

This should do what you need it to do..

This will sweep all inputs, to the specified output address (minus the fee)

@abeikverdi
Copy link

@ac0uk while this works and sends the entire input, it sometimes breaks the outputs to two for me with a very random logic. any idea why this is happening? There is no point in creating two outputs which results in paying higher fees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants