4

So, after understanding how to create and send raw transactions on the basis of 'How to send from many bitcoin addresses to one bitcoin address?', in practice I still struggle with transaction fees. For example, I do the following in order to calculate the size of an hex-encoded transaction:

hex_raw_transaction = createrawtransaction(...)
hex_raw_transaction = signrawtransaction(hex_raw_transaction)
byte[] size = HexStringToByteArray(hex_raw_transaction)
int transaction_size = size.Length

Is that a correct way to determinate the transaction size? (Regarding to https://en.bitcoin.it/wiki/Transaction_fees)?

Is it correct that the transaction fee is set by the unassigned amount in the outputs?

For example, if I have 1 BTC in one address and send the 0.65 BTC to a second address and 0.3495 BTC as change to the first

//The fee will be: 
fee = 1 - (0.65 + 0.3495)  //= 0.0005 btc

is it correct that the fee will be 0.0005 BTC?

Arsenius
  • 239
  • 1
  • 10

1 Answers1

2

Here is a great answer on how to calculate the transaction size before sending. (Make sure to read the final edit.)

As for the fee, you've got it right: whatever amount from the inputs is NOT sent to other addresses, becomes the transaction fee for the miners.

timetofly
  • 201
  • 2
  • 9
  • Yes it exactly the same value size of transaction if we use bitcoind getrawtransaction command, e.g. bitcoind getrawtransaction d9804de366aa4c2a01565c3a3c8aa2ea20baafc276dc875f80b9044841205333 return 15522 length of hex-string, so in real bytes it will be 7761 whcih is actual size of transaction – Arsenius Sep 17 '13 at 15:26