0

I am attempting to build a working withdrawal system where users can withdraw funds in BTC. I am required to estimate the fee before allowing them to withdraw to include it in their payment. I was able to determine the maximum estimated fee based on inputs and outputs of the transaction. I had assumed that the transactions would have 1 input and 2 outputs as when I was testing that was the outcome. I am now seeing transactions with multiple inputs and outputs making the transaction size larger, therefore, increasing the fee. This is problematic for me as I am having to pay for these fees. I need to be able to determine the inputs and outputs of the transaction before I send it to the blockchain.

0

If you are constructing your own transactions (rather than letting a wallet application do it for you), then you get to choose which inputs and outputs you use in the transaction. For that matter, you also get to choose the fee for the transaction, since any leftover from the sum of the inputs minus the sum of the outputs is the mining fee. Just remember that leaving too low of a fee will result in long delays of unconfirmed transactions.

Based on your needs, you can choose to use different coin selection algorithms. A coin selection algorithm's purpose is to select inputs from the pool of UTXOs that you control. Selecting too many for a single transaction will result in a higher fee. However, refusing to use smaller UTXOs will leave your entire pool comprised of small ones, forcing you to use them (and pay higher fees) until your pool recovers.

There are pros and cons to different algorithms, especially when you are concerned with fees, so be sure to understand the ramifications of your decision. A good place to start might be @Murch's presentation at Scaling Bitcoin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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