Latest Articles

Dollar gains, stocks teeter as US data suggests rates to stay higher

The dollar rose and a gauge of global equities slid on Thursday after data once again highlighted persistent U.S. labor market strength, suggesting the...
HomeCryptoBitcoin's fee mechanism

Bitcoin’s fee mechanism

When people promote Bitcoin , they often say: “You can transfer money to various Zhang San and Li Si for free.” In fact, it is not necessarily, and sometimes a handling fee is required.

In 2013, the price of one bitcoin was $20. In 2017, it cost $20 to transfer one bitcoin.

The purpose of the fee is to encourage miners to keep mining, and secondly to maintain the security of the Bitcoin network (stability maintenance fee?). The basic salary of the early miners is relatively high, 50 BTC per block , but after the genesis block, the basic salary is halved for every 210,000 blocks (every four years). After all 21 million bitcoins have been mined, transaction fees act as mining rewards.

The code for the halving algorithm looks like this.

CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)

The reward was halved from 50 bitcoins to 25 bitcoins in 2012, and halved from 25 bitcoins to 12.5b bitcoins in 2016. In about 2020, there will be another halving to 6.25 bitcoins.

So, how do you determine when you need to pay transaction fees and how much is appropriate?

The Bitcoin network rules have a built-in transaction fee structure that depends on the (standard) client side recommended by the system. Let’s take bitcoin core as an example to see which steps are required when transferring money:

  1. What coins do you spend?

The client first determines which coins to use to complete the payment.

For example, Bob transfers 2 bitcoins to Alice; Rose transfers 3 bitcoins to Alice, then the two transfer amounts will lie in Alice’s wallet separately until they are spent. (Note: two transfers will not be “auto-merged” to 5BTC).

Then, after a while, different amounts of bitcoins will accumulate in the wallet, so it is said that you have to consider which ones to use for payment.

The available amount is called the “input” of the transaction, and the final amount sent (including change back to the wallet) is called the “output”.

  1. Avoid overly piecemeal payments

If the transaction “output” (including change) is less than 0.01BTC, a handling fee of 0.0001BTC will be charged. When “selection of coins”, the algorithm will try to avoid those coins whose change amount is less than 0.01BTC.

  1. Old coins and large-value transactions are preferred

If the amount of bitcoin sent is too small, or the coin age is too low, it is likely to be charged. Each transaction has a priority, determined by the age of the “input”, the amount, and the number of transaction inputs.

Specifically, the client multiplies the amount of each input by the time the input exists in the block, adds all the multiplication results and divides it by the transaction size in bytes.

If the result is less than 0.576, a transaction fee will be charged. So, if you have a bunch of fragmented and/or very new “inputs”, and you don’t want to pay the fees, you can do it by adding a large and older input to the transaction. Here, what is more critical is the average value of this amount x age.

If a transaction was originally charged in step 3, but as time passes, new blocks are continuously generated, then the “input” age in the original transaction also increases, which further enhances the priority of the transaction, so Fees incurred in step 3 may be waived.

  1. “Weighing” charges (charged per kilobyte)

Finally, the client checks the byte length of the transaction. The length depends on the number of inputs and outputs and can be roughly calculated by the following formula:

148 * number of inputs + 34 * number of outputs + 10

If the length is less than 10000 bytes and there is a high enough priority in step 3, then the transaction is finally confirmed as free, otherwise it will be charged. The default fee is 0.0001BTC/kilobyte (if it is less than 1k, it will be calculated as 1k) . You can change the transaction fee amount in the client-side related settings. Settings below 0.0001BTC will not take effect. After the new fee setting takes effect, the fee in step 2 will be overwritten, and the two will not be superimposed.

Then a few examples:

  1. Too much

Say: Alice has two “inputs” in her wallet, with the amount of 1BTC and 2BTC respectively. Then Alice wants to buy a cup of coffee for 2.99999BTC. At this time, there is no such thing as choosing coins, because there are only two inputs, and both of them are enough for coffee money, and the remaining 0.00001BTC is used for change. Note that step 2 mentioned: If the transaction “output” (including change) is less than 0.01BTC, a handling fee of 0.0001BTC will be charged. Note, coffee transactions will be charged a handling fee of 0.0001BTC. The result is that the transaction fails because Alice does not have enough balance in her hand.

This is interesting: Alice has 3BTC on hand, but cannot buy 2.99999BTC of coffee. Alice can pay the merchant all 3BTC to avoid the fee (assuming the fee in step 3 is 0), but some merchants may ask for the exact amount.

  1. Personality outbreak

Said: Alice’s personality broke out. In a gambling game with odds of 64000, she used 0.02BTC to transfer 1280BTC. When the website paid the bonus, I didn’t have the 1280BTC in my wallet, so I could only use various pieces of input (including change) to make up.

In the end, the total size of the bonus is 51203 bytes. That’s right, if the transaction size exceeds 10,000 bytes, the fee increases to 0.0005BTC/kbyte (in fact, the transaction fee in the early stage was 0.0005, and later became 0.0001), then the fee here is 52*0.0005 = 0.026BTC. Higher than the player’s book.

Of course, it’s still cheaper than PayPal.

Note: The handling fee for using Paypal is 4.4% + 0.3 USD per transaction.

For example, 1280 dollars transfer, 1280*4.4% + 0.3 = 56.62 dollars

Note: The final fee paid is 0.0286BTC. It may be because the standard client (recommended) was not used to create the transaction, and then this client has a small problem in calculating the fee.

This is a real thing, see: Bitcoin Transaction 0a05beb2b1ad62d54a40e624d763cd97f10369b8e0527a3046dd2562cef4652c

  1. The agency does all the calculations and does not pay

There is a kind of transaction that is on the edge of the free cliff, with a size of 9999 bytes, which is called the king of transaction fee dodging. Only one of the total inputs is 1 satoshi (the smallest unit of Bitcoin, 0.000 000 01 BTC = 1 satoshi, in tribute to Bitcoin founder Satoshi Nakamoto); but there is another large input that raises the priority and exempts transactions cost.

Do I have to pay a handling fee?

By the way, the handling fee is actually not mandatory. Some miners don’t pay much attention to these fees and will record some transactions without fees in the block. Transactions with lower fees than standard fees can be created using the “raw transactions” interface of the standard client, and there is still a chance that a burst of character can be packaged into blocks by miners.