Since the activation of Segwit, transaction size is expressed in Weight Units (WU). Weight Units can be converted to a "virtual size" or virtual bytes (vB) by dividing by 4 and rounding up. The virtual size dictates how large your transaction is when paying fees.
For now, let's focus on Non-Segwit transactions. Each Non-Segwit byte ...
Similarly to how a browser decodes a bunch of text, which is arranged in accordance with a certain protocol (html), and creates a nice interface you can view (provided it has all the right pieces, so starts with , has all matching <> for tags, etc, otherwise your browser displays an error or a garbage page) ...
A bitcoin node will decode a bunch of text,...
Depending on the type of transaction,
inputs, outputs and other factors..add them all up here is a link to bitcoin docs giving byte size for everything https://en.bitcoin.it/wiki/Protocol_documentation#tx
I wrote some code to calculate an estimate for multisig transaction size based on Karimkorun's almost unreadable answer and based off the (incomplete) documentation here.
var pubkeySize = 33
var sigSize = 72
// An approximation based on the example in
var pubkeyScriptSize = 25
var m = 2, n ...
You need to take a look at how fee_estimates.dat is written and interpreted. Basically it's composed of:
With CURRENT being "when writing", i.e. when stopping bitcoind.
Here is the method writing the file, and here is the method reading this file (at startup). I ...
So how we can calculate txn fee before signing and sending txn for external addresses?
As a reference:
P2PKH P2SH-P2WPKH P2WPKH
Input : 592 WU 364 WU 272 WU
Output : 136 WU 128 WU 124 WU
All transactions include 40 WU by default. If your transaction spends a P2SH-P2WPKH or P2WPKH ...
"fundrawtransaction" and "walletcreatefundedpsbt" are wallet RPCs. They add inputs and change outputs from your wallet to aim for a specific feerate for the transaction.
These operations inherently require the relevant wallet. Change addresses are generated by the sender's wallet, and inputs have to come from the wallet of the sender. If you don't have that ...
If you want to implement your coin selection, the only alternative to calculating the fee manually I can think of is the following:
You select which inputs you want to be used in your transaction based on your coin selection algorithm.
You then proceed to lock every input that is not the one you selected. You can get the list of all inputs through ...