Title: How to retrieve transaction fee? Post by: supermoney on January 12, 2016, 08:38:14 PM I'm coding a specific PHP script that requires to retrieve the fee from a received transaction.
Let's focus on the following transactions that I received on my own testnet address: Transaction with fees: 7f502f28ca8d162300a1bbc8cb7dfa6f38533596ac97c29e1d1de9ca614ae350 (https://www.blocktrail.com/tBTC/tx/7f502f28ca8d162300a1bbc8cb7dfa6f38533596ac97c29e1d1de9ca614ae350) Transaction with no fees: 9afe2bf122e4ec26cff427015ea680f4e03877077376d1d9b1c6d6f63563acc7 (https://www.blocktrail.com/tBTC/tx/9afe2bf122e4ec26cff427015ea680f4e03877077376d1d9b1c6d6f63563acc7) I couldn't figure out how to get the fee out of the transactions, so can you suggest me all possible methods? Thank you! I'm actually storing all send-receive transactions on my database through blocknotify + walletnotify + gettransaction. PS: do not confuse my help request with calculating the fee of transactions prematurely before sending. Title: Re: How to retrieve transaction fee? Post by: cr1776 on January 12, 2016, 08:57:13 PM For:
7f502f28ca8d162300a1bbc8cb7dfa6f38533596ac97c29e1d1de9ca614ae350 Total Inputs 11.69569708 tBTC Total Outputs -11.69563674 tBTC = 0.00006034 tBTC fees (subtracting total outputs from total inputs) For the second, total inputs and total outputs are the same: 506.68468049 tBTC So there are 0.0 fees. Does that make sense? If you aren't asking how to calculate the fees for that transaction as it was confirmed, I am not sure what you are asking. Title: Re: How to retrieve transaction fee? Post by: supermoney on January 12, 2016, 09:03:20 PM For: 7f502f28ca8d162300a1bbc8cb7dfa6f38533596ac97c29e1d1de9ca614ae350 Total Inputs 11.69569708 tBTC Total Outputs -11.69563674 tBTC = 0.00006034 tBTC fees (subtracting total outputs from total inputs) For the second, total inputs and total outputs are the same: 506.68468049 tBTC So there are 0.0 fees. Does that make sense? If you aren't asking how to calculate the fees for that transaction as it was confirmed, I am not sure what you are asking. I'm actually doing it via Bitcoin API and PHP. I tried gettransaction but it doesn't print the fee amount. UPDATE: now tried getrawtransaction (with verbose) and could finally get the output value but not the input value. Title: Re: How to retrieve transaction fee? Post by: achow101 on January 12, 2016, 09:08:59 PM I'm actually doing it via Bitcoin API and PHP. I tried gettransaction but it doesn't print the fee amount. gettransaction will not give you the fee if you received the transaction, only if you sent. You should use getrawtransaction. With that command you can retrieve the vout values of all of the outpoints of the inputs and the output. Then just use those the calculate the fee.Title: Re: How to retrieve transaction fee? Post by: cr1776 on January 12, 2016, 09:11:13 PM For: 7f502f28ca8d162300a1bbc8cb7dfa6f38533596ac97c29e1d1de9ca614ae350 Total Inputs 11.69569708 tBTC Total Outputs -11.69563674 tBTC = 0.00006034 tBTC fees (subtracting total outputs from total inputs) For the second, total inputs and total outputs are the same: 506.68468049 tBTC So there are 0.0 fees. Does that make sense? If you aren't asking how to calculate the fees for that transaction as it was confirmed, I am not sure what you are asking. I'm actually doing it via Bitcoin API and PHP. I tried gettransaction but it doesn't print the fee amount. You might try using getrawtransaction and then subtracting the outputs from the inputs. This has some more info: http://bitcoin.stackexchange.com/questions/11411/in-getrawtransaction-what-is-the-vout-integer-in-the-vin-list Title: Re: How to retrieve transaction fee? Post by: supermoney on January 12, 2016, 09:11:41 PM I'm actually doing it via Bitcoin API and PHP. I tried gettransaction but it doesn't print the fee amount. gettransaction will not give you the fee if you received the transaction, only if you sent. You should use getrawtransaction. With that command you can retrieve the vout values of all of the outpoints of the inputs and the output. Then just use those the calculate the fee.For: 7f502f28ca8d162300a1bbc8cb7dfa6f38533596ac97c29e1d1de9ca614ae350 Total Inputs 11.69569708 tBTC Total Outputs -11.69563674 tBTC = 0.00006034 tBTC fees (subtracting total outputs from total inputs) For the second, total inputs and total outputs are the same: 506.68468049 tBTC So there are 0.0 fees. Does that make sense? If you aren't asking how to calculate the fees for that transaction as it was confirmed, I am not sure what you are asking. I'm actually doing it via Bitcoin API and PHP. I tried gettransaction but it doesn't print the fee amount. Yeah I've figured it out few minutes ago but as I've said in my previous post there's no input value: Code: { Title: Re: How to retrieve transaction fee? Post by: cr1776 on January 12, 2016, 09:12:45 PM ... Yeah I've figured it out few minutes ago but as I've said in my previous post there's no input value: ... The link above may have what you are looking for. Title: Re: How to retrieve transaction fee? Post by: supermoney on January 12, 2016, 09:59:32 PM ... Yeah I've figured it out few minutes ago but as I've said in my previous post there's no input value: ... The link above may have what you are looking for. Ok thanks, I've missed that :D UPDATE: it took me few minutes to get it, correct me if I'm wrong -> http://pastebin.com/keYrsW46 Code: <?php Title: Re: How to retrieve transaction fee? Post by: achow101 on January 12, 2016, 10:52:54 PM ... Yeah I've figured it out few minutes ago but as I've said in my previous post there's no input value: ... The link above may have what you are looking for. Ok thanks, I've missed that :D UPDATE: it took me few minutes to get it, correct me if I'm wrong -> http://pastebin.com/keYrsW46 Code: <?php Title: Re: How to retrieve transaction fee? Post by: supermoney on January 12, 2016, 10:58:40 PM Thank you for the fast reply I really appreciate, however I've done many tests on various txs and my script worked like a charm.
#closed. |