user43354: 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 ? 

user3697: 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>


43354: <p>In our application we are generating a trasaction hex using the <code>createrawtransaction</code> 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 <code>estimatefee x</code> 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. </p>

<p>So the question is: what's the best way to estimate the optimal mining fee while using <code>createrawtransaction</code> ? </p>
 3697: <p>Have a look at <code>fundrawtransaction</code> (if you are okay using the internal wallet).
<code>fundrawtransaction</code> will give you back the used <code>fee</code> (next to the hex byte-array of the funded transaction) before signing or broadcasting the transaction.</p>
<h2>The ideal workflow is:</h2>
<ul>
<li><code>createrawtransaction '[]' '{&quot;&lt;addr&gt;&quot;: &lt;amount&gt;}' //set no inputs</code></li>
<li><code>fundrawtransaction &lt;hex&gt;</code></li>
<li>you'll get back <code>{&quot;hex&quot;:&lt;tx&gt;, &quot;fee&quot;: &lt;amount&gt;, &quot;changepos&quot;: &lt;pos of the change output&gt;}</code></li>
<li>Check the fee, maybe increase it (requires Bitcoin Core 0.14, use the <code>feeRate</code> of <code>fundrawtransaction</code>.</li>
<li><code>signrawtransaction &lt;hex&gt;</code></li>
<li><code>sendrawtransaction &lt;hex&gt;</code></li>
</ul>
