Hello,
I'm creating an application which allows users to have their own addresses from which they can deposit/withdraw from. When users withdraw from an address generated from my wallet to their own personal wallet, I'd like to account for fees and let users aware of these fees before actually withdrawing.
My initial idea to do this would go as follows:
1) User inputs a desired value that they want to withdraw which sends a request to my backend
2) I then create a "mock" transaction (whether is be by manually creating it or with fundrawtransaction)
3) Get the resultant the number of inputs/outputs of the transaction/the resultant tx size in bytes
4) Use this resultant tx size to estimate the actual fee based off a certain feerate
Note: this feerate will be decided by user and based on whether they want a faster tx time w/ lower fees or a slower tx time w/ higher fees
5) Add this fee to the total withdraw amount
However, this seems to be a bit "overkill" since every time a user enters a value to withdraw (even if they do not go through with it), I'd have to create a new transaction and this seems unnecessarily intensive.
Another idea I had was to ignore the part of actually creating the transaction but instead checking the minimal amount of transaction inputs/outputs that I'd need for the transaction with something like listunspent and then calculate the total tx fee with the formula: (n_in*148 + n_out*34 + 10) * feerate.
As a follow up question, would I then have to create raw transactions to properly implement these fees? It seems that the JSON RPC commands like sendtoaddress and fundrawtransaction do not provide enough flexibility when setting user fees.
Any input would be appreciated! And if there is anything that I seem to be confused/wrong about, please let me know