1

Help me please. I need to calculate vsize and multiply it by the function result estimatesmartfee. To calculate vsize, I implement a formula like this https://jlopp.github.io/bitcoin-transaction-size-calculator/ byt i cannot getting address type from Bitcoin API.

Please tell me how to get the address type by API for implementing this formula?

2
  • 1
    Related: bitcoin.stackexchange.com/a/67896/26873
    – m1xolyd1an
    Commented Jun 18, 2020 at 13:25
  • 1
    Perhaps this is somehow related to my question, but I did not understand how to determine which type the address from which I send funds and the address to which I send funds according to the following types, belong to? P2PKH P2SH P2WPKH in P2SH P2WSH in P2SH P2WPKH P2WSH P2TR If you can more details please
    – ArchiKu
    Commented Jun 18, 2020 at 13:44

1 Answer 1

1
  • P2PKH: Starts with "1". Commonly known as "Legacy Address". They have a known vbyte size. Size to spend is predictable.
  • P2SH: Starts with "3". You would know if you made a P2SH address, since they're almost always involved with n-of-m multisig. Vary in size depending on how many parties are involved in the multisig. Size to spend is unknown unless the wallet you're spending from knows how to spend it or you created the transaction manually.
  • P2WPKH in P2SH: Starts with "3". Commonly known as "Segwit Address". Quickly becoming, if not already, the most common address type. They have a known vbyte size. Size to spend is predictable.
  • P2WSH in P2SH: Starts with "3". Likewise with P2SH, you'd know if you made this type of address as it's involved in n-of-m multisig. Vary in size depending on how many parties are involved in the multisig. Size to spend is known unless the wallet you're spending from knows how to spend it or you created the transaction mnually.
  • P2WPKH: Starts with "bc1q". Commonly known as "Native Segwit Address". They have a known vbyte size. Size to spend is predictable.
  • P2WSH: Just like P2SH but starting with "bc1q" and much longer than a P2WPKH address.
  • P2TR: No idea what this is unfortunately. Looks like it stands for "Pay 2 Taproot". But I admit that I don't know much about Taproot, and I don't think this has been implemented on mainnet yet.

Please tell me how to get the address type by API for implementing this formula?

I don't know what API you're referring to, but if you are running a Bitcoin Node you can run the command bitcoin-cli getaddressinfo "YOUR_ADDRESS_HERE" to get information about a particular address. Note that for addresses starting with "3", you will not be able to determine if it is P2WPKH in P2SH vs. P2SH, as they are indistinguishable from each other until spent. They will both have "isscript": true. For "bc1q" addresses, they will both have "iswitness": true and P2WSH will also have "isscript": true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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