blocktrail-sdk-php
blocktrail-sdk-php copied to clipboard
Estimate optimal fee
Can we get a function to get an estimate of the optimal fee? I would like to see how much the fee would cost to send X satotshi
The coinSelection method returns the fee for your requested fee rate, assuming you provide a list of outputs you are trying to pay. There isn't a way to estimate the fee to move X BTC, because fees are based on the transactions byte size, so it's necessary to know how many inputs there will be before you can know the transactions size (and fee).
If you don't need reproducable results you could set $lockUTXOs = false
on the coinSelection call, which will give you a fee, but be aware that any spends that happen afterwards might affect the inputs it prefers, and the fee..
Alternatively, you could take the size of a 1 input, and a 2 input transaction from your wallet, and assuming the number of outputs & address type doesn't change, you can work out how large an input is (IIRC it's ~300 bytes), then make a formula to estimate the tx size for n
inputs using the feeRate call.
Estimated Input Size: Size_2_Input_tx - Size_1_input_tx Estimated size: EstimatedInputSize * (n - 1) + Size_1_input_tx Estimated fee: EstimatedSize * $sdk->feePerKb()[$feeStrategy]
If your UTXO's are usually larger than your output amount, its safe to assume it'll be a 1 or 2 input transaction, and estimate accordingly
Would be nice to see option for pay
function to pay $amount - $calculatedFee
to simulate "recipient pays fee".