Bitcoin Forum
May 09, 2024, 01:01:23 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: bitcoind RPC calls: get fee amount of received transaction  (Read 1652 times)
binaryFate (OP)
Legendary
*
Offline Offline

Activity: 1484
Merit: 1003


Still wild and free


View Profile
July 07, 2013, 10:40:12 PM
 #1

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?


Monero's privacy and therefore fungibility are MUCH stronger than Bitcoin's. 
This makes Monero a better candidate to deserve the term "digital cash".
1715216483
Hero Member
*
Offline Offline

Posts: 1715216483

View Profile Personal Message (Offline)

Ignore
1715216483
Reply with quote  #2

1715216483
Report to moderator
1715216483
Hero Member
*
Offline Offline

Posts: 1715216483

View Profile Personal Message (Offline)

Ignore
1715216483
Reply with quote  #2

1715216483
Report to moderator
I HATE TABLES I HATE TABLES I HA(╯°□°)╯︵ ┻━┻ TABLES I HATE TABLES I HATE TABLES
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
grue
Legendary
*
Offline Offline

Activity: 2058
Merit: 1431



View Profile
July 07, 2013, 10:56:14 PM
 #2

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.

It is pitch black. You are likely to be eaten by a grue.

Adblock for annoying signature ads | Enhanced Merit UI
binaryFate (OP)
Legendary
*
Offline Offline

Activity: 1484
Merit: 1003


Still wild and free


View Profile
July 07, 2013, 11:14:51 PM
 #3

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.

Monero's privacy and therefore fungibility are MUCH stronger than Bitcoin's. 
This makes Monero a better candidate to deserve the term "digital cash".
btc4ever
Sr. Member
****
Offline Offline

Activity: 321
Merit: 250


View Profile
July 07, 2013, 11:19:39 PM
 #4

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.


 
 
 

Psst!!  Wanna make bitcoin unstoppable? Why the Only Real Way to Buy Bitcoins Is on the Streets. Avoid banks and centralized exchanges.   Buy/Sell coins locally.  Meet other bitcoiners and develop your network.   Try localbitcoins.com or find or start a buttonwood / satoshi square in your area.  Pass it on!
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
July 08, 2013, 03:03:15 AM
 #5

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.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
binaryFate (OP)
Legendary
*
Offline Offline

Activity: 1484
Merit: 1003


Still wild and free


View Profile
July 08, 2013, 10:47:04 AM
 #6

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

Monero's privacy and therefore fungibility are MUCH stronger than Bitcoin's. 
This makes Monero a better candidate to deserve the term "digital cash".
binaryFate (OP)
Legendary
*
Offline Offline

Activity: 1484
Merit: 1003


Still wild and free


View Profile
July 09, 2013, 11:52:46 AM
 #7

Bump

Monero's privacy and therefore fungibility are MUCH stronger than Bitcoin's. 
This makes Monero a better candidate to deserve the term "digital cash".
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
July 09, 2013, 12:39:25 PM
 #8

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."
binaryFate (OP)
Legendary
*
Offline Offline

Activity: 1484
Merit: 1003


Still wild and free


View Profile
July 09, 2013, 03:17:49 PM
 #9

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.

Monero's privacy and therefore fungibility are MUCH stronger than Bitcoin's. 
This makes Monero a better candidate to deserve the term "digital cash".
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
July 09, 2013, 05:49:49 PM
 #10

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.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
binaryFate (OP)
Legendary
*
Offline Offline

Activity: 1484
Merit: 1003


Still wild and free


View Profile
July 09, 2013, 05:56:57 PM
 #11

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.

Monero's privacy and therefore fungibility are MUCH stronger than Bitcoin's. 
This makes Monero a better candidate to deserve the term "digital cash".
NielDLR
Member
**
Offline Offline

Activity: 95
Merit: 10



View Profile WWW
July 10, 2013, 03:10:48 AM
 #12

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.

The Cypherfunks - A decentralized band and cryptocurrency. The first cryptocollective.
binaryFate (OP)
Legendary
*
Offline Offline

Activity: 1484
Merit: 1003


Still wild and free


View Profile
July 10, 2013, 11:13:14 AM
 #13

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.


Monero's privacy and therefore fungibility are MUCH stronger than Bitcoin's. 
This makes Monero a better candidate to deserve the term "digital cash".
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!