-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How to get incoming transaction fee #10734
Comments
You will need to use getrawtransaction and then do the math. So using this txid as an example : e198d4b193644116d9df0b9d65c4346a9f4d6214a46ffba8c0b2fd6999eda314
Now what you need to do is to calculate the number of fees, is to look inside vin and take the vout number. So in this example the vout number is 0. And then you go to vout and add the value of all the output together. Now you will have to do another getrawtransaction on the vin txid. Which in our example will give us this :
So here, what you have to look for is, in vout, the n value that is equal to the previous number you got, so in our case it's 0. You take the value of this output which is 7.04418967 BTC. And now to calculate the fees, you take this number minus the previous value you got which give you : fees = 7.04418967 - (4.00000000 + 3.04192967) Hope this will help you out. |
Given that this is (technically) publicly available information - it would be great if the fee would be calculated and then added to the result object returned by This would also significantly reduce the load on a server being used to calculate fees as consumers would no longer need to hit the bitcoin node more than once for any single transaction (assuming they want to calculate fees) |
yeah, i would also say the fee should be shown there |
fee() {
tx=$(bitcoin-cli getrawtransaction $1 1)
vin=$(jq -r '.vin[] | "\(.txid) \(.vout)"' <<< $tx | while read txid vout; do bitcoin-cli getrawtransaction $txid 1 | jq -r ".vout[$vout].value"; done | paste -sd+ | bc)
vout=$(jq '.vout[].value' <<< $tx | paste -sd+ | bc)
printf '%0.8f' $(bc <<< "$vin - $vout")
}
|
You can use |
These really are not great solutions. gettransaction is where the CALCULATED fee data belongs. getrawtransaction doesnt work with pruned nodes (otherwise whats the point of pruned mode), getblock doesnt return the fee for the specific TXID we need and isnt even the right section anyway, and some sort of absurd and nearly impossible to read bash script is the very definition of "hacky". Currently fees only show for OUTGOING TXs that the wallet sent. Incoming TXs do not have this data entry in gettransaction. |
Hi.
I have a question I couldn't find an easy solution for it.
I'm working to automate CPFP (child pays for parent) for incoming stuck transactions and want to make sure that the new transaction will have the fee so the resulting fee per byte will be set to the current network conditions, so the stuck transaction(s) will be quickly confirmed.
The problem is I can't determine the fee of the incoming transactions arriving to the wallet via
gettransaction
rpc call.Here is an example:
Bitcoin isn't returning the fee. fee is only returned if I send outgoing transactions.
Is there any way to determine what fee was set for incoming transaction(s) (via JSON-RPC)?
Thank you.
The text was updated successfully, but these errors were encountered: