TransWikia.com

How to get address type(format). Need to calculate vsize and fee

Bitcoin Asked by ArchiKu on October 24, 2021

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?

One Answer

  • 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.

Answered by Septem151 on October 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP