Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: ronmike on January 25, 2018, 11:14:22 AM



Title: How to calculate transaction fees ?
Post by: ronmike on January 25, 2018, 11:14:22 AM
I am using bitcore server https://github.com/bitpay/bitcore and below is the code for making a transaction

Code:

var tx = bitcore.Transaction();
tx.from(utxos);
tx.to(address2,50000);
tx.change(address);
tx.sign(privateKey);
tx.serialize();

How much transaction fees are taken for executing the above transaction.? and I want to check before the transaction goes for the execution.


Title: Re: How to calculate transaction fees ?
Post by: AGD on January 25, 2018, 12:24:54 PM
You can read everything about Bitcoin fees here: https://en.bitcoin.it/wiki/Transaction_fees


Title: Re: How to calculate transaction fees ?
Post by: Marrying_Couch on January 25, 2018, 03:44:20 PM
You can read everything about Bitcoin fees here: https://en.bitcoin.it/wiki/Transaction_fees

all is available here, we just understand what we do not understand, so no one in the deal.


Title: Re: How to calculate transaction fees ?
Post by: akiash on January 25, 2018, 05:00:31 PM
You can read everything about Bitcoin fees here: https://en.bitcoin.it/wiki/Transaction_fees

Hi AGD,
I would really appreciate if you could give me piece of advice on this. What is the best way to send cryptocurrency from one exchange to another. I can see that if I send BTC, is has higher fees.


Title: Re: How to calculate transaction fees ?
Post by: Stedsm on January 25, 2018, 06:16:58 PM
You can read everything about Bitcoin fees here: https://en.bitcoin.it/wiki/Transaction_fees

Hi AGD,
I would really appreciate if you could give me piece of advice on this. What is the best way to send cryptocurrency from one exchange to another. I can see that if I send BTC, is has higher fees.

That's something already fixed that you're asking about. Exchanges charge a "fixed" fee for a transaction that they execute on their end and you are bound to pay those fees if you are withdrawing your coins from an exchange to exchange or even a wallet. You can only decide fee while you are sending "your" coins that you have in your wallet, and not an exchange. The "fixed" fee charged by them is what they take per transaction, not the fee they actually send while sending you your "withdrawn" amount. One more thing, each exchange has different "fixed" fee levels, like Polo charges 0.0005 BTC per withdrawal, Bittrex takes 0.001 BTC and so on.


Title: Re: How to calculate transaction fees ?
Post by: Salmen on January 25, 2018, 07:32:55 PM
If no fee is given, a transaction with an optimal fee according to the size and network traffic will be sent. Otherwise, if a custom-fee is given which can be done like the example on the below, you overwrite the fee amount.

Code:
var transaction = new Transaction()
    .from(utxos)          // Feed information about what unspent outputs one can use
    .to(address, amount)  // Add an output with the given amount of satoshis
    .change(address)      // Sets up a change address where the rest of the funds will go
    .sign(privkeySet)     // Signs all the inputs it can
var transaction = new Transaction().fee(5430); // Minimum non-dust amount
var transaction = new Transaction().fee(1e8);  // Generous fee of 1 BTC

To record this transaction on the blockchain, you have to serialize the variable transaction, and thereby, push to the network through https://blockchain.info/pushtx (https://blockchain.info/pushtx).

Source: https://bitcore.io/api/lib/transaction (https://bitcore.io/api/lib/transaction)


Title: Re: How to calculate transaction fees ?
Post by: akiash on January 25, 2018, 09:14:40 PM
You can read everything about Bitcoin fees here: https://en.bitcoin.it/wiki/Transaction_fees

Hi AGD,
I would really appreciate if you could give me piece of advice on this. What is the best way to send cryptocurrency from one exchange to another. I can see that if I send BTC, is has higher fees.

That's something already fixed that you're asking about. Exchanges charge a "fixed" fee for a transaction that they execute on their end and you are bound to pay those fees if you are withdrawing your coins from an exchange to exchange or even a wallet. You can only decide fee while you are sending "your" coins that you have in your wallet, and not an exchange. The "fixed" fee charged by them is what they take per transaction, not the fee they actually send while sending you your "withdrawn" amount. One more thing, each exchange has different "fixed" fee levels, like Polo charges 0.0005 BTC per withdrawal, Bittrex takes 0.001 BTC and so on.
Thanks. That helps. Recently I transferred some BTC from coinbase to binance and they charged me around 18 USD for that transaction. If I'm going to transfer some money from binance to other exchange, what is the best format of cryptocurrency I should send in order to minimize the fees.


Title: Re: How to calculate transaction fees ?
Post by: AGD on January 26, 2018, 06:03:27 AM
You can read everything about Bitcoin fees here: https://en.bitcoin.it/wiki/Transaction_fees

Hi AGD,
I would really appreciate if you could give me piece of advice on this. What is the best way to send cryptocurrency from one exchange to another. I can see that if I send BTC, is has higher fees.

That's something already fixed that you're asking about. Exchanges charge a "fixed" fee for a transaction that they execute on their end and you are bound to pay those fees if you are withdrawing your coins from an exchange to exchange or even a wallet. You can only decide fee while you are sending "your" coins that you have in your wallet, and not an exchange. The "fixed" fee charged by them is what they take per transaction, not the fee they actually send while sending you your "withdrawn" amount. One more thing, each exchange has different "fixed" fee levels, like Polo charges 0.0005 BTC per withdrawal, Bittrex takes 0.001 BTC and so on.
Thanks. That helps. Recently I transferred some BTC from coinbase to binance and they charged me around 18 USD for that transaction. If I'm going to transfer some money from binance to other exchange, what is the best format of cryptocurrency I should send in order to minimize the fees.

Most of the Altcoins have a lower fee, but you will lose some % when you want to exchange back in BTC.


Title: Re: How to calculate transaction fees ?
Post by: cry4crypto on January 26, 2018, 02:03:05 PM
There are also multiple online fee calculators out there if you don't feel like calculating yourself. To name a few:

https://estimatefee.com/
http://bitfees.info/
https://www.cheaperfee.com/
https://coinb.in/#fees

I am in no way affiliated with any of these sites by the way, but hope you find either of them useful.


Title: Re: How to calculate transaction fees ?
Post by: buwaytress on January 26, 2018, 03:07:47 PM
To add in on the other answers here, since OP still wants to know how to calculate tx fees... the most important piece of information you need is the size of your transactions. Doesn't seem to be in those lines of code, but they do have pieces of info that you can use to estimate size (not very accurately but close enough):

- number of inputs you're using, a
- number of outputs you'll create, b

Then: a*180 + b*34 + 10 +/- 1

which is why a 1 input, 1 output tx, the most common one, results in a typical tx size of 225 bytes. If you're using SegWit, your txs are going to be smaller (edit: added "in weight"), so this is a safe formula to use.

Easiest for me is to use the rough formula automatically done in site suggested above (estimate fee) so that's your best point to start finding out tx size, and then you crosscheck with another estimator with an easier to see structure like bitcoinfees.earn.com to see how much you need to pay per byte, for the estimated confirmation time you're comfortable with.


Title: Re: How to calculate transaction fees ?
Post by: achow101 on January 26, 2018, 04:03:10 PM
Then: a*180 + b*34 + 10 +/- 1
Unless you are using uncompressed public keys (and very few wallets do this anymore), the input multiplier will be 148 instead of 180.


Title: Re: How to calculate transaction fees ?
Post by: Carlton Banks on January 26, 2018, 06:07:59 PM
and then you crosscheck with another estimator with an easier to see structure like bitcoinfees.earn.com to see how much you need to pay per byte, for the estimated confirmation time you're comfortable with.

Strongly recommend against using bitcoinfees.earn.com (which is the same as bitcoinfees.21.co), especially for those that aren't familiar with Bitcoin fee estimating, bitcoinfees.21.co/bitcoinfees.earn.com suggests incorrect estimates for confirmation times.

The text delivering the "answer" is highly misleading: "The fastest and cheapest transaction fee is currently: 220 satoshis/byte" (which at this point in time is around 10 times more than an equally fast fee rate).

The site's conf-time estimate seems to erroneously deem the "cheapest and fastest" fee to be that which is paid very near to the highest within the top 1MB of it's mempool, when in fact every transaction within the top 1MB will be equally fast (yet not equally cheap).

It's likely no coincidence that 200 sat/byte transactions are heavily represented in the typical Bitcoin mempool. Very little mempool space is occupied inbetween this so called "cheapest and fastest" threshold and the lowest fee within the top 1 MB of the mempool (which is 10 times lower than 200 sat/byte right now).

Their method for calculating fees therefore always presents users with a false impression of confirmation times, and likely distorts the fee market against the user's interests. I am most embarrassed to have recommended this website in the past.


Title: Re: How to calculate transaction fees ?
Post by: hatshepsut93 on January 26, 2018, 09:31:06 PM
and then you crosscheck with another estimator with an easier to see structure like bitcoinfees.earn.com to see how much you need to pay per byte, for the estimated confirmation time you're comfortable with.

Strongly recommend against using bitcoinfees.earn.com (which is the same as bitcoinfees.21.co), especially for those that aren't familiar with Bitcoin fee estimating, bitcoinfees.21.co/bitcoinfees.earn.com suggests incorrect estimates for confirmation times.


Probably the best way to check the current fees is to go to https://dedi.jochen-hoenicke.de/queue/#2h and look at the mempool size to see what fees are getting included in recent blocks by looking at spike drops. Also, this should be another incentive to run a full node, as SPV clients have to trust their servers to get fee estimations (correct me if I'm wrong).


Title: Re: How to calculate transaction fees ?
Post by: buwaytress on January 27, 2018, 10:00:49 AM
and then you crosscheck with another estimator with an easier to see structure like bitcoinfees.earn.com to see how much you need to pay per byte, for the estimated confirmation time you're comfortable with.

Strongly recommend against using bitcoinfees.earn.com (which is the same as bitcoinfees.21.co), especially for those that aren't familiar with Bitcoin fee estimating, bitcoinfees.21.co/bitcoinfees.earn.com suggests incorrect estimates for confirmation times.

The text delivering the "answer" is highly misleading: "The fastest and cheapest transaction fee is currently: 220 satoshis/byte" (which at this point in time is around 10 times more than an equally fast fee rate).

The site's conf-time estimate seems to erroneously deem the "cheapest and fastest" fee to be that which is paid very near to the highest within the top 1MB of it's mempool, when in fact every transaction within the top 1MB will be equally fast (yet not equally cheap).

It's likely no coincidence that 200 sat/byte transactions are heavily represented in the typical Bitcoin mempool. Very little mempool space is occupied inbetween this so called "cheapest and fastest" threshold and the lowest fee within the top 1 MB of the mempool (which is 10 times lower than 200 sat/byte right now).

Their method for calculating fees therefore always presents users with a false impression of confirmation times, and likely distorts the fee market against the user's interests. I am most embarrassed to have recommended this website in the past.


Thanks for pointing that out... I confess I haven't been looking at the explanation paragraphs below the main charts for months and you're right. The graphs themselves are still helpful, I've always used the estimation with confirmation times that more or less correspond. But the "cheapest and fastest" estimation is definitely far from accurate, at least it is right now.

I've been recommending this estimator for months now so am as guilty for possibly getting other users to pay more fees than needed. Complacency...

I do note that the graphs themselves are still a useful tool but now should find something more representative.

Then: a*180 + b*34 + 10 +/- 1
Unless you are using uncompressed public keys (and very few wallets do this anymore), the input multiplier will be 148 instead of 180.

I learn something new every day here, thanks for pointing that out!


Title: Re: How to calculate transaction fees ?
Post by: Carlton Banks on January 29, 2018, 12:38:14 PM
I confess I haven't been looking at the explanation paragraphs below the main charts for months and you're right. The graphs themselves are still helpful, I've always used the estimation with confirmation times that more or less correspond. But the "cheapest and fastest" estimation is definitely far from accurate, at least it is right now.

I've been recommending this estimator for months now so am as guilty for possibly getting other users to pay more fees than needed. Complacency...

Yeah, like I said, I have recommended bitcoinfees.21.co in the past without fully understanding how inaccurate it's estimates can be. And like you said, the raw information on the site is perfectly usable, but those looking for a simple answer are likely to assume the estimation (or even the "fastest & cheapest") figures are good, which they're not.


Title: Re: How to calculate transaction fees ?
Post by: Hans17 on February 05, 2018, 07:17:37 AM
You can read everything about Bitcoin fees here: https://en.bitcoin.it/wiki/Transaction_fees

Wow didn't know about this and thank you though it really help me and to be honest I am doing some basic search about this , and now I know , thank's a lot though and for my opinion how to calculate the fees I think by the demand of it however the bitcoin or the cryptocurrency's price.


Title: Re: How to calculate transaction fees ?
Post by: Ulap16 on February 06, 2018, 04:24:47 AM
I didn't know anything about transaction fees and so much information is available here. I'll do my own research now and try to calculate the fees.