Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: sebicas on January 10, 2013, 08:29:31 PM



Title: This transaction requires a transaction fee of at least 0.0215 because of ...
Post by: sebicas on January 10, 2013, 08:29:31 PM
Can somebody tell me how is this amount calculated?

Thanks!


Title: Re: This transaction requires a transaction fee of at least 0.0215 because of ...
Post by: gmaxwell on January 10, 2013, 09:07:38 PM
Can somebody tell me how is this amount calculated?
Thanks!

Your transaction doesn't qualify as free, so it's applying 0.0005  BTC per 1000 bytes of transaction data. Your transaction is 43kilobytes in size. A basic transaction is about 230 bytes in size. Your transaction is likely so large because something has been paying you in very tiny coins.

E.g. it's like you asked for all your change in pennies and now that bank wants a fee to handle the big sack you're turning in to deposit.


Title: Re: This transaction requires a transaction fee of at least 0.0215 because of ...
Post by: DannyHamilton on January 10, 2013, 10:21:29 PM
The code can be found in GetMinFee() in main.cpp (https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp).

First a fee is calculated by dividing the size of the transaction (in bytes) by 1000, adding one to the integer quotient, and multiplying the sum by 0.0005 (nBaseFee) . . .
Quote
int64 nMinFee = (1 + (int64)nBytes / 1000) * nBaseFee;

If the total size (in bytes) of the transaction is less than 10kB, then the client lets you send it without the fee . . .
Quote
if (nBytes < 10000)
    nMinFee = 0;

However, if any output is less than 0.01, then a the client decides you need a fee after all . . .
Quote
if (txout.nValue < CENT)
    nMinFee = nBaseFee;

After all that, if the fee is bigger than 21,000,000 BTC, then it gets reduced to exactly 21,000,000 BTC.
Quote
if (!MoneyRange(nMinFee))
    nMinFee = MAX_MONEY;


Title: Re: This transaction requires a transaction fee of at least 0.0215 because of ...
Post by: dooglus on January 11, 2013, 09:28:27 PM
If the total size (in bytes) of the transaction is less than 10kB, then the client lets you send it without the fee . . .
Quote
if (nBytes < 10000)
    nMinFee = 0;

Except that there's also a check made to make sure that the coins you are spending are old enough and big enough to qualify for no fee.  It multiplies the age of the coin (in days) by the value of the coin (in BTC) and needs to get more than 1 for the spend to be free.

For example, a 12 BTC coin only needs to be 2 hours old to not incur a fee when it's spent (12 * 2/24 == 1) but a 0.01 BTC coin needs to be 100 days old before it can be spent without a fee.

If you're spending multiple coins at once, it sums the product of value and age over all the coins you're spending, and if that sum is greater than 1, the coins are deemed big/old enough.  So you can spend the 2 hour old 12 BTC coin and a brand new 0.01 BTC coin without a fee if you spend them both at once.


Title: Re: This transaction requires a transaction fee of at least 0.0215 because of ...
Post by: sebicas on January 12, 2013, 09:17:08 AM
Thanks for all the answers!


Title: Re: This transaction requires a transaction fee of at least 0.0215 because of ...
Post by: etotheipi on January 13, 2013, 04:02:27 AM
Whoa, didn't the allow-free criteria for transaction size used to be like 4 kB?  I have definitely been using 4 kB ever since Armory was first released...

I'll go ahead and update that...