Author

Topic: calculation fee from change (Read 1049 times)

legendary
Activity: 3472
Merit: 4801
November 24, 2015, 10:04:51 AM
#5
More example please.
- snip -

Sure.  Lets grab a random transaction out of the blockchain and take a look at it. I'll pick txID 44d1430102af06489c1a82ae7bb285f684e32a849907b2e11aca67651ac5e292 for this example:

The transaction spends, as an input, the second output (vout=1) of transaction 452d20b51161a8177ce40fa569a26947406d1dae9e40f8472948623d06356ede.
The sum of the values of all the inputs is 26.85898588 BTC.

It sends 3 BTC to 1FeFue5cHarn2B8ntC4wWdfY7eJa3nyUgY
It sends 23.85888588 BTC to 141SFBdbrK9YD4J71LqJw7Fb9vqwYfSmeX
The sum of the values of all the outputs is 26.85888588 BTC.

This leaves 0.0001 BTC unaccounted for in the transaction.  All unaccounted for amounts are defined as transaction fees.  Therefore, since the transaction used 26.85898588 BTC of value for the inputs and only 26.85888588 BTC for the outputs, the miners take the unaccounted for 0.0001 BTC and pay it to themselves as a transaction fee.

Using createrawtransaction in Bitcoin Core the transaction could have been created as follows:

Code:
createrawtransaction [{\"txid\":\"44d1430102af06489c1a82ae7bb285f684e32a849907b2e11aca67651ac5e292\",\"vout\":1}] {\"1FeFue5cHarn2B8ntC4wWdfY7eJa3nyUgY\":3.0, \"141SFBdbrK9YD4J71LqJw7Fb9vqwYfSmeX\": 23.85888588}
copper member
Activity: 1498
Merit: 1528
No I dont escrow anymore.
November 24, 2015, 04:58:33 AM
#4
More example please. Found next
Code:
sendrawtransaction "hexstring" ( allowhighfees )
if i add allowhighfees option it will calculate from change automatic ? 

No, this will only allow you to pay a high fee.

An example would be you have 2 inputs worth 2 BTC each (so 4 BTC in total) and want to spend 2.5 BTC with a 0.001 BTC fee.

You would create an output for 2.5 BTC to the address of the recipient and an output of (4-2.5-0.001) 1.499 BTC as change to an address of yourself. The fee will be the rest. You dont have to set the fee directly when creating a rawtransaction.

Maybe sendfrom[1] is what you are looking for?

[1] https://bitcoin.org/en/developer-reference#sendfrom
jr. member
Activity: 43
Merit: 7
November 24, 2015, 03:33:48 AM
#3
More example please. Found next
Code:
sendrawtransaction "hexstring" ( allowhighfees )
if i add allowhighfees option it will calculate from change automatic ? 
copper member
Activity: 1498
Merit: 1528
No I dont escrow anymore.
November 23, 2015, 07:18:11 AM
#2
Fee = sum of inputs - sum of outputs

The fee is every satoshi you do not spend in one of the outputs. You can substract that from the change or from the payment, but usually change makes more sense.
jr. member
Activity: 43
Merit: 7
November 23, 2015, 06:27:49 AM
#1
Hello,

prepared rawTx by all tx output, added destination and change address

Code:
'{"sedtination":11, "change":9}'

how to calculate fee ? can I add fee automatically from change ?

Thanks.
Jump to: