Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: DaMan on June 09, 2011, 09:20:54 PM



Title: PHP: how to calculate the transaction fee?
Post by: DaMan on June 09, 2011, 09:20:54 PM
Hi!

I have a big problem i can't solve by myself:

I am using PHP and use the API "sendfrom" command to send some transactions.

Is there a way to calculate the exactly needed transaction fee? I tried it with a basic 2% calculation and if I send i.e. 2 BTC I check if my account balance is more than 2 BTC + 2%.

But if I am sending more transactions it results in an error, because the account balance is to low.

Is there a way/command to calculate the correct transactions fee needed for each transaction? Or a way to get the transaction KB value?

Kind regards,

DaMan


Title: Re: PHP: how to calculate the transaction fee?
Post by: winnetou on August 05, 2011, 03:35:59 AM
Have you found a solution for your problem?


Title: Re: PHP: how to calculate the transaction fee?
Post by: talpan on August 05, 2011, 06:24:12 AM
Hi!

I have a big problem i can't solve by myself:

I am using PHP and use the API "sendfrom" command to send some transactions.

Is there a way to calculate the exactly needed transaction fee? I tried it with a basic 2% calculation and if I send i.e. 2 BTC I check if my account balance is more than 2 BTC + 2%.

But if I am sending more transactions it results in an error, because the account balance is to low.

Is there a way/command to calculate the correct transactions fee needed for each transaction? Or a way to get the transaction KB value?

Kind regards,

DaMan


There is currently no way to calculate the resulting fees, afaik.


Title: Re: PHP: how to calculate the transaction fee?
Post by: arsenische on October 03, 2011, 02:05:48 PM
There is currently no way to calculate the resulting fees, afaik.

but bitcoin software does it somehow.. probably just need to look at sources


Title: Re: PHP: how to calculate the transaction fee?
Post by: maaku on October 03, 2011, 04:29:49 PM
What fee it calculates depends on what transaction outputs it decides to use to fund the new transaction, and (I could be wrong with this point) I don't believe it does so deterministically. So there certainly isn't a way to do it without all the information in wallet.dat, and that might not even be enough.


Title: Re: PHP: how to calculate the transaction fee?
Post by: Pieter Wuille on October 04, 2011, 08:14:30 AM
What fee it calculates depends on what transaction outputs it decides to use to fund the new transaction, and (I could be wrong with this point) I don't believe it does so deterministically. So there certainly isn't a way to do it without all the information in wallet.dat, and that might not even be enough.

This is correct.

I believe the solution is providing an RPC call that creates a preliminary transaction (which isn't broadcast yet), but can be inspected. At this point, it can either be committed (broadcast) or reverted through another RPC call.


Title: Re: PHP: how to calculate the transaction fee?
Post by: kjj on October 04, 2011, 01:16:56 PM
What fee it calculates depends on what transaction outputs it decides to use to fund the new transaction, and (I could be wrong with this point) I don't believe it does so deterministically. So there certainly isn't a way to do it without all the information in wallet.dat, and that might not even be enough.

This is correct.

I believe the solution is providing an RPC call that creates a preliminary transaction (which isn't broadcast yet), but can be inspected. At this point, it can either be committed (broadcast) or reverted through another RPC call.

Yup, but it needs to lock all transactions involved in the potential spend until it gets approval / rejection / timeout.  For almost all systems that I can think of, this is worse than just paying the fee and noting the amount later.