In our application we are generating a trasaction hex using the createrawtransaction call to "handcraft" a transaction. The problem we are facing is that we would like to estimate the mining fee for this transaction. I realize that we could call estimatefee x to estimate the mining fee per byte. But the problem is we are generating the transaction, so we don't know the size of the transaction yet! Chicken or egg?! I realize that we can generate a transaction and then account for the mining fee based on the hex, but this sounds like a hack to me.

So the question is: what's the best way to estimate the optimal mining fee while using createrawtransaction ?

1 Answer 1


Have a look at fundrawtransaction (if you are okay using the internal wallet). fundrawtransaction will give you back the used fee (next to the hex byte-array of the funded transaction) before signing or broadcasting the transaction.

The ideal workflow is:

  • createrawtransaction '[]' '{"<addr>": <amount>}' //set no inputs
  • fundrawtransaction <hex>
  • you'll get back {"hex":<tx>, "fee": <amount>, "changepos": <pos of the change output>}
  • Check the fee, maybe increase it (requires Bitcoin Core 0.14, use the feeRate of fundrawtransaction.
  • signrawtransaction <hex>
  • sendrawtransaction <hex>
  • This is a great suggestion! But we want to spend from a particular address in the wallet which we retrieve from listunspent .. so it won't work for us as there is no way to do this filtering in fundrawtransaction
    – motatoes
    Commented Feb 7, 2017 at 10:21
  • In that case you need to calculate the transaction size by yourself by assume 72byte per EC sig. But it depends what types of inputs you support (P2PKH, etc.). Commented Feb 7, 2017 at 19:40
  • Well they are all multisig addresses .. So P2SH
    – motatoes
    Commented Feb 7, 2017 at 21:05

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.