pybitcash/bitcash

How do I get the actual fee before sending the transaction?

Closed this issue · 6 comments

I find an explanation in bitcash:
bitcash.network.fees import get_fee
Fee = get_fee(speed='medium')

Fee = 4

the fee displayed on the real network,let me name it realFee
Fee != realFee(904 satoshi)
What did bitcash do to calculate the value of realFee?
I want to get the actual fee before sending the transaction.
I look forward to your reply.

Those low, medium, high variables are just hardcoded numbers for satoshis per byte... like recommended satoshis per byte but at the present moment has zero intelligence and doesn't connect to any 3rd parties or anything... it is a stopgap measure as I understand it until something better replaces it.

If you directly throw in fee = 1, 2 or 3 etc.. into a key.send (... fee=1) command or any of those other "create transaction" type functions, it will calculate the fee as 1, 2 or 3 sat/byte respectively... fee calculation should work pretty nice now after recently being fixed.

You can infer from that and the size of the rawtx that you're about to send what the fee will be. Is this a documentation issue more than anything maybe?? Like you can just do len (rawtx in bytes) and immediately know what it will cost you (by multiplying by what fee level you will pick)

Thank you for your answer.
I am very much looking forward to a better solution.
Now how can I get the size of the rawtx of transaction?

I don't know if this is right? But the calculated value is equal to the fee of real network.
fee_byte = get_fee()
tx_hex_len = len(tx_hex)
tx_hex_half = tx_hex_len/2
fee = fee_byte * (tx_hex_half+1)

I don't know why it is calculated like this. This is the regular pattern I observed.

By the way, will the value of get_fee() be updated periodically when bitcash get the latest fee value in the api? In some places, the code is not consistent with the comments, so I am confused. And some apis of bch recently seem to be unstable

Do a length on the transaction, I guess it should be hex so divide by two.

Eventually will use an api to pull recommended fee values, for now it's hard coded.

Yes, there's lots broken. Feel free to send PRs.

Why are you so concerned about fee amounts? They are super low in Bitcoin Cash.

I am not worried about whether it's fee is too high. The fee of bch is lower than other virtual currency I know. In fact, I just want to let the sender know the fees to be spent before the transaction, so that they don't need to worry if this trade will exceed their budget, or the balance on his account.
thank you very much.@cyborg0922 @teran-mckinney.
Your patient explanation has benefited me a lot.