Author

Topic: bitcoind RPC calls: get fee amount of received transaction (Read 1664 times)

legendary
Activity: 1512
Merit: 1012
Still wild and free
Thanks a lot NielDLR!  Smiley

Make a pull request. Don't bitch about it, this is open source software, either code it yourself or shut up.
I presume you're "answer" is for me. I perfectly know how an open source project works and would never "bitch" about it. Where did you see that I complained?
I asked this question because among all possible API calls I may have missed one that suits my need. I don't thank you sir for your useless post and your harsh tone out of nowhere.

member
Activity: 95
Merit: 10
That's what I had in mind, thanks for writing this down precisely.
My latest concern is that when I'll do this:
Then, loop through the vins and do another lookup on each of them

bitcoind might complain that it cannot find the transaction (as it is not linked to my wallet addresses in any way)
I couldn't test yet if it works, if it works only with "txindex=1", if does not work at all (I fear once all outputs are spent the information won't remain anywhere locally)... I'll try soon.

I've recently done a similar thing for a bitcoin project.
You'll have to set txindex=1 and then run bitcoind again with the -reindex flag. When you use getrawtransaction again, it will work on all possible transactions, regardless if all the outputs have been spent or not.

Then, as kjj mentioned, loop through vouts (add them up) and then lookup each vin using getrawtransaction on the txid. However, you might be confused on how to find the exact output amount for your vin. The vout parameter in the vin is a reference to which output it refers to from your input.

Look below:

Code:
"vin": [
    {
      "txid": "2da6ea77348c20885a7d80969bc67eadbb41bbcd817cd154c85f84979661a248",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022046778cb18a3dbec25959e9426de06219241233ebe173db8b1b090f7162daa7ec022100ab5bc2ced0f77046c5aba10000a1884dc1dcdc3991ab3106f6ac664ef7b4add801 023763e069253c6dfeab973e069d4f2461abac442135bf8ffd484ff0e7ca3f9762",
        "hex": "483045022046778cb18a3dbec25959e9426de06219241233ebe173db8b1b090f7162daa7ec022100ab5bc2ced0f77046c5aba10000a1884dc1dcdc3991ab3106f6ac664ef7b4add80121023763e069253c6dfeab973e069d4f2461abac442135bf8ffd484ff0e7ca3f9762"
      },
      "sequence": 4294967295
    }
  ],

The vout is 1. Now if you run a getrawtransaction on that txid you'll see this in the vout:

Code:
"vout": [
    {
      "value": 0.9,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 60d602d14e71717373101521eafb5c1f8f8904d3 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a91460d602d14e71717373101521eafb5c1f8f8904d388ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "19q2FAM1MkdBHiUvhvQheh2RvbpUEZ3xx4"
        ]
      }
    },
    {
      "value": 4.7305,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 694239b7dcd7b05f291add07bcf98c5d92e4ab64 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914694239b7dcd7b05f291add07bcf98c5d92e4ab6488ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1AbZHZwa9oAbVpiWsESrozUwNwx4H3kHFY"
        ]
      }
    }
  ],

n:1 is the one you're looking for. Thus the value is 4.7305.

Now add up all the values for all the vins of the original transaction and minus the vouts = fee.
legendary
Activity: 1512
Merit: 1012
Still wild and free
That's what I had in mind, thanks for writing this down precisely.
My latest concern is that when I'll do this:
Then, loop through the vins and do another lookup on each of them

bitcoind might complain that it cannot find the transaction (as it is not linked to my wallet addresses in any way)
I couldn't test yet if it works, if it works only with "txindex=1", if does not work at all (I fear once all outputs are spent the information won't remain anywhere locally)... I'll try soon.
kjj
legendary
Activity: 1302
Merit: 1026
Code:
bitcoind getrawtransaction 946a49aca6fad0cc95792d70fd189ff4f3ca2e113da89c7780a2c2e9a73df41d 1

Replace that txid with the txid you want to see.

Basically, you look up the transaction you want to see.  Loop through the vouts and add up the values.  Then, loop through the vins and do another lookup on each of them, add up those values.*  Subtract the second value from the first value, and you have the fee.

* When something is a vin here, it was a vout in a previous transaction.  You look up that previous transaction by txid using the same call as above, then just ignore everything except the vout that you need.
legendary
Activity: 1512
Merit: 1012
Still wild and free
Perhaps a future version will add an additional API for this, but at the moment the only way you can find the information is by "looping over vin and vouts to compute the difference of the sums."

Gosh!  Sad
Thanks Danny for the clarity.
I'm not sure how I can loop over the vins actually. They don't include amounts, just a reference to which vouts of other transactions they refer. Even with "txindex=1", how can I query bitcoind about these transactions as they have nothing to do with my wallet addresses?... I'll try, but I have doubt I can get info about them.
legendary
Activity: 3472
Merit: 4801
Perhaps a future version will add an additional API for this, but at the moment the only way you can find the information is by "looping over vin and vouts to compute the difference of the sums."
legendary
Activity: 1512
Merit: 1012
Still wild and free
legendary
Activity: 1512
Merit: 1012
Still wild and free
I'm sure you could puzzle it out by using the raw transaction decoder.

Yes I could, by doing this:
To get this fee amount, I would like to avoid looping over vin and vouts to compute the difference of the sums
But I'm surprised I cannot get this piece of information as an explicit field from bitcoind.
For instance I can get the amount of the transaction with gettransaction or getrawtransaction, I don't have to sum all the vout myself. I'm asking if there's an equivalent for fees.

But why would you do that?  Unless you are also the miner of the block that included that transaction, you don't care about the fee: It isn't yours.
I know it's not mine, but I'd like to know this anyway. For instance, I could check how much the transaction complies with 0.8.2+ rules, or I could estimate the time to be included in a block. I don't think the "why?" is relevant to my question anyway.  Smiley
kjj
legendary
Activity: 1302
Merit: 1026
I'm sure you could puzzle it out by using the raw transaction decoder.

But why would you do that?  Unless you are also the miner of the block that included that transaction, you don't care about the fee: It isn't yours.
sr. member
Activity: 321
Merit: 250
The OP was asking how a recipient could determine what fees were paid by sender.  I'm not sure that's possible.  anyone?

there is no reliable to determine what fees the client will use. patches are welcome, but the preferred solution is to set the tx fee to 0.0001 BTC by default, and deduct that from your customer.

Somehow the bitcoin-qt UI is able to display the required fee amount to the user with a proceed/cancel dialog.  So it seems like the same thing should be possible via RPC api, by hooking into the code the UI uses.   I envision something like: 

  send_handle = rpc.prepareSend();
  meta = rpc.getMeta(send_handle);
  if( meta.fee > limit )
      abort();
  else
      rpc.send( send_handle );


This is a serious pain point for developers trying to use bitcoind for anything real.


 
 
 
legendary
Activity: 1512
Merit: 1012
Still wild and free
there is no reliable to determine what fees the client will use. patches are welcome, but the preferred solution is to set the tx fee to 0.0001 BTC by default, and deduct that from your customer.

Either I didn't explain my question properly, or you read it a bit fast  Smiley

I don't want to know what fee will be used, but to know the fee included in a transaction I received from somebody else.
legendary
Activity: 2058
Merit: 1452
there is no reliable to determine what fees the client will use. patches are welcome, but the preferred solution is to set the tx fee to 0.0001 BTC by default, and deduct that from your customer.
legendary
Activity: 1512
Merit: 1012
Still wild and free
Dear all,

I don't find a convenient way with bitcoind rpc calls, to determine the fee amount of a transaction I receive.
I found the information on the wiki to be wrong or outdated on this:
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list#Common_operations
'gettransaction' is said to return the fee, but I found that it is true only for transaction of type "send", not "receive".

Maybe there is another place where I can find more reliable info on the bitcoind RPC calls?

To get this fee amount, I would like to avoid looping over vin and vouts to compute the difference of the sums, there must be something easier! Am I missing something?

Jump to: