How to estimate mining fee for raw transaction? 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 ?
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 '[]' '{&quot;&lt;addr&gt;&quot;: &lt;amount&gt;}' //set no inputs
fundrawtransaction &lt;hex&gt;
you'll get back {&quot;hex&quot;:&lt;tx&gt;, &quot;fee&quot;: &lt;amount&gt;, &quot;changepos&quot;: &lt;pos of the change output&gt;}
Check the fee, maybe increase it (requires Bitcoin Core 0.14, use the feeRate of fundrawtransaction.
signrawtransaction &lt;hex&gt;
sendrawtransaction &lt;hex&gt;