python – calculate transaction fee

0
15


I have been trying to write an application for transferring bitcoin programmatically using python and bit library. However, I’m currently stuck on how to calculate transaction fee.

from bit import Key
from bit import wif_to_key

key = Key('key_is_ommited')
key.get_unspents()

targetwallet="key_is_ommited"
amountasbtc = 0.00007
x = key.send([(targetwallet, amountasbtc, 'btc')], fee=102)
print(x)

I understand that the fee 102 is in satoshi per kb and I need to “guesstimate” how much kb the transaction going to be so I can “guesstimate” how much the fee going to be. when this question was written the transaction is about $12 in cost.

and also I found out Bit library has a function to measure transaction size with this formula:

(42 + 272×(number of inputs) + 128×(number of outputs))/4

is input = 1 (bitcoin wallet address)
and outputs is = 2 (1 destination address and 1 change address)?

so if I’m sending to 5 address that means is about 6 output?



Source link

Leave a reply