1

We're using bitcoind on our server.

When people withdraw from our system we want to have the correct miner fee.

I understand that we can get the good miner fee from txconfirmtarget or the API from: https://bitcoinfees.21.co/api

But when we send a transaction how do we know which miner fee to put if we want to enter it into the database?

EDIT: I do notice this: bitcoin-cli estimatefee 2 but then how do we find out how many bytes are being sent?

4
  • Are you using bitcoind's internal wallet or just using it to create and broadcast a raw transaction?
    – Ava Chow
    Commented Jul 5, 2017 at 23:17
  • bitcoind on a centos server Commented Jul 6, 2017 at 16:25
  • That doesn't answer my question. Are you using bitcoind as a wallet (i.e. using sendtoaddress, sendmany, etc. RPCs) or just as a node to broadcast your transactions with?
    – Ava Chow
    Commented Jul 6, 2017 at 16:31
  • as a wallet with RPCs Commented Jul 6, 2017 at 16:37

1 Answer 1

1

When you use bitcoind's internal wallet and its related RPCs, it will automatically calculate the transaction fee for you and include that in the transaction. You can then retrieve the transaction fee used by using the gettransaction command. If you want the fee rate that was used, you can use the fee from gettransaction and divide that by the size returned by gettransaction.

Edit: To get the fee before you send, you can create the transaction with only the outputs you want (i.e. no inputs) with createrawtransaction. Then you can use fundrawtransaction to fill out the transaction with inputs. That will also give you the fee that the transaction is paying. Then you sign it with signrawtransaction and send it with sendrawtransaction. There is no other way as the other send* RPCs create the transaction, select coins, sign, and send all in one command.

4
  • But I want to estimate the fee before the transaction is sent. Commented Jul 6, 2017 at 20:03
  • I've edited with further instructions to get the fee before the transaction is sent.
    – Ava Chow
    Commented Jul 6, 2017 at 20:32
  • Thanks for the update. So basically I do createrawtransaction and fundrawtransaction and it returns the size of the transaction, then I can set a custom fee based on how many bytes it is.. then of course sendrawtransaction. Commented Jul 6, 2017 at 20:52
  • No, you can't set the fee after the transaction has been created. The fee has to be set when the transaction is being funded. fundrawtransaction has an option to set the fee rate. Just read the help text for it.
    – Ava Chow
    Commented Jul 6, 2017 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.