bit icon indicating copy to clipboard operation
bit copied to clipboard

Calculate fee or trx size

Open voxcdr opened this issue 4 years ago • 7 comments

https://github.com/ofek/bit/issues/106

I have the same need to calculate the fee amount, or deduct the fee amount from the transfer amount. Otherwise, a bug will appear.

Let's say you have 1 bitcoin on your balance and you need to transfer the entire balance. If you specify 1 bitcoin for the transfer, you will receive an error not enough funds. How to correctly calculate the maximum value for a transfer, taking into account the fee?

voxcdr avatar Jan 11 '21 12:01 voxcdr

Normally, this is how we do it: https://ofek.dev/bit/guide/transactions.html#transfer-funds

ghost avatar Jan 11 '21 17:01 ghost

looks like kludge

voxcdr avatar Jan 12 '21 05:01 voxcdr

It might appear as such to you, but that is the exact high level representation of how a wallet sweep actually works 😉

ofek avatar Jan 12 '21 06:01 ofek

It's not about wallet sweep at all. Don't you find the problem is that it is not possible to calculate the exact fee and include it in the transfer amount? After all, it is also necessary to check the balance for availability. Conventionally, if there is 0.1 bitcoin on the wallet and I need to transfer 0.99997, the transaction will not go through with the "insufficient balance" error.

voxcdr avatar Jan 12 '21 06:01 voxcdr

The fee calculation function was fixed in https://github.com/ofek/bit/pull/109/files

ofek avatar Jan 12 '21 06:01 ofek

Can I get more information about func arguments: in_size, n_in, out_size, n_out ?

voxcdr avatar Jan 12 '21 06:01 voxcdr