Author

Topic: How to retrieve transaction fee? (Read 844 times)

legendary
Activity: 1161
Merit: 1004
January 12, 2016, 05:58:40 PM
#10
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.
staff
Activity: 3458
Merit: 6793
Just writing some code
January 12, 2016, 05:52:54 PM
#9
legendary
Activity: 1161
Merit: 1004
January 12, 2016, 04:59:32 PM
#8
...
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  Cheesy

UPDATE: it took me few minutes to get it, correct me if I'm wrong -> http://pastebin.com/keYrsW46

Code:
require_once("src/class.connector.php");
$rpc = new Connector("username""password""127.0.0.1""18333");
$txid "7f502f28ca8d162300a1bbc8cb7dfa6f38533596ac97c29e1d1de9ca614ae350";
$txinfo $rpc->getrawtransaction($txid1);                                         // get info from received tx
$txinput $txinfo["vin"][0]["txid"];                                                // result: fd018b006c8702139d1c230460c1a71f99d364d59c339e26cc8588cf622a5be9
$spent round($txinfo["vout"][0]["value"] + $txinfo["vout"][1]["value"], 8);        // result: 0.73000000 + 10.96563674 = 11.69563674
$txinfo $rpc->getrawtransaction($txinput1);                                      // get info from input tx of received tx
$fee round($txinfo["vout"][1]["value"] - $spent8);                               // result: 11.69569708 - 11.69563674 = 0.00006034
print($fee);
?>

legendary
Activity: 4228
Merit: 1313
January 12, 2016, 04:12:45 PM
#7
...
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.
legendary
Activity: 1161
Merit: 1004
January 12, 2016, 04:11:41 PM
#6
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:
{
"hex" : "0100000001e95b2a62cf8885cc269e339cd564d3991fa7c16004231c9d1302876c008b01fd010000006b483045022100f49467a7ce7ace56013da6edda79e0091cc8add647b2085f7d2d3f7fed5b6e8c0220581a2c0a0d6b492a3c31b90cc626b374b7f08c61c61852a620d4d1323055435c012103478900f6438292ae0020d519d48de9dcadb821a154762de7ab3f637c6c1dc8c5feffffff0240e45904000000001976a91441a6de7575fa51462507f74662692093d0dea98088acda3b5c41000000001976a914b8f24e7b733aa6834272fe5b09d2fdcecdc1493e88ac02a80900",
"txid" : "7f502f28ca8d162300a1bbc8cb7dfa6f38533596ac97c29e1d1de9ca614ae350",
"version" : 1,
"locktime" : 632834,
"vin" : [
{
"txid" : "fd018b006c8702139d1c230460c1a71f99d364d59c339e26cc8588cf622a5be9",
"vout" : 1,
"scriptSig" : {
"asm" : "3045022100f49467a7ce7ace56013da6edda79e0091cc8add647b2085f7d2d3f7fed5b6e8c0220581a2c0a0d6b492a3c31b90cc626b374b7f08c61c61852a620d4d1323055435c01 03478900f6438292ae0020d519d48de9dcadb821a154762de7ab3f637c6c1dc8c5",
"hex" : "483045022100f49467a7ce7ace56013da6edda79e0091cc8add647b2085f7d2d3f7fed5b6e8c0220581a2c0a0d6b492a3c31b90cc626b374b7f08c61c61852a620d4d1323055435c012103478900f6438292ae0020d519d48de9dcadb821a154762de7ab3f637c6c1dc8c5"
},
"sequence" : 4294967294
}
],
"vout" : [
{
"value" : 0.73000000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 41a6de7575fa51462507f74662692093d0dea980 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a91441a6de7575fa51462507f74662692093d0dea98088ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"mmW67nNBnNMkaXfM44NMgtCo7VrXbByP2F"
]
}
},
{
"value" : 10.96563674,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 b8f24e7b733aa6834272fe5b09d2fdcecdc1493e OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914b8f24e7b733aa6834272fe5b09d2fdcecdc1493e88ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"mxNru78e56ysyGwdsT6UY3iHZrsDLXiStM"
]
}
}
],
"blockhash" : "000000000000186eec98d20a64afe351562f4805c26e6a688705895e77c1138e",
"confirmations" : 10,
"time" : 1452630788,
"blocktime" : 1452630788
}
legendary
Activity: 4228
Merit: 1313
January 12, 2016, 04:11:13 PM
#5
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
staff
Activity: 3458
Merit: 6793
Just writing some code
January 12, 2016, 04:08:59 PM
#4
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.
legendary
Activity: 1161
Merit: 1004
January 12, 2016, 04:03:20 PM
#3
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.
legendary
Activity: 4228
Merit: 1313
January 12, 2016, 03:57:13 PM
#2
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.
legendary
Activity: 1161
Merit: 1004
January 12, 2016, 03:38:14 PM
#1
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
Transaction with no fees: 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.
Jump to: