Help me work out a transaction fee I am having difficulty working out how to work out a transaction fee.  I've read the theory, but don't understand how to get the values to put the theory to practice.

Can someone please help me work this out step by step?  If I want to send 0.05XBT from: mvDLEEymmEijZXyrrNRL3aPMhH8q2m8vE1 to mxgxQ52kYRVPfLeYpXugkCAGhjLfUaZk3g.  How do I work out the transaction fee?

If your answer could use these public keys so I can try them out based on the instructions in your answer, I would really appreciate that.

Using bitcoin-qt's command line, I have the following details:


  listunspent [ { "txid" :
  "9df9c897af413505c02f158a7421b39000b40248a3bb826831ff458aee84f8ca",
  "vout" : 1, "address" : "mvDLEEymmEijZXyrrNRL3aPMhH8q2m8vE1",
  "account" : "From http://faucet.xeno-genesis.com/", "scriptPubKey" :
  "76a914a134b5919d09350f6232260ed1313f73ac6b7bae88ac", "amount" :
  1.19994817, "confirmations" : 364 } ]


Then I could use this:


  createrawtransaction
  '[{"txid":"d3be60aaf98ef888a9137928fa405806cd2e0c762f5205b3d9ba3e6ad26a5262","vout":1}]'
  '{"mxgxQ52kYRVPfLeYpXugkCAGhjLfUaZk3g":0.05,"mvDLEEymmEijZXyrrNRL3aPMhH8q2m8vE1":1.14974817
  }'


But this "assumes" a 0.0002XBT fee.

I can then sign the transaction like so:


  signrawtransaction
  '010000000162526ad26a3ebad9b305522f760c2ecd065840fa287913a988f88ef9aa60bed30100000000ffffffff02404b4c00000000001976a914bc5e62709adc296640dfed6871f0ebff5a7d11c588ac6160da06000000001976a914a134b5919d09350f6232260ed1313f73ac6b7bae88ac00000000'
  '[{"txid" :
  "d3be60aaf98ef888a9137928fa405806cd2e0c762f5205b3d9ba3e6ad26a5262","vout"
  : 1,"scriptPubKey" :
  "76a914a134b5919d09350f6232260ed1313f73ac6b7bae88ac"}]' '["private key
  here"]'


Which gives me this:


  010000000162526ad26a3ebad9b305522f760c2ecd065840fa287913a988f88ef9aa60bed3010000006b483045022100f447788e6b40a1f8bd22b084c8507a7710bd5c8cb33b08082c308a7a0edc86d402204024287053715bc096e56744e45683bb63b32ebe56a2f2070fd318216512641d012103ca4eab4b394090c9f4c10b6a9c2674dfc14c7dee55b6d3eb72c4263fc325c37effffffff02404b4c00000000001976a914bc5e62709adc296640dfed6871f0ebff5a7d11c588ac6160da06000000001976a914a134b5919d09350f6232260ed1313f73ac6b7bae88ac00000000


Which is 452 bytes.

Apparently I am supposted count the number of inputs and outputs too?  I understand that the fee can get more complex based on the age of the transaction and if I send a very small amount.  But just for example purposes, How would I work out the transaction fee using the 2 public keys above if I wanted to send 0.05XBT? so I can subtract the fee from the change when using the createrawtransaction command in bitcoin-qt?
I can calculate the priority of the transaction (527 confirmations currently, ~452 bytes):

119994817 * 527 / 452 = 139,905,461


Since this is over the minimum of 57,600,000 and meets the other rules for free transactions: namely, that the transaction is under 1000 bytes and has no outputs under 0.01 BTC, this transaction can be free. You do not need to include a transaction fee: make the sum of the outputs equal the input amount exactly.

If your transaction didn't meet the requirements for a free transaction, or if you don't wish it to be treated as a free transaction (which have some limits in transmitting, etc. that might slow down their inclusion in a block), you would need to include 0.0001 BTC transaction fee per thousand bytes (e.g. up to 1000 bytes is 0.0001, 1001-2000 bytes is 0.0002, etc.)

(this is assuming the testnet has the same rules for transaction fees as Bitcoin's mainnet)