简体   繁体   English

比特币核心 - 如何在将 BTC 发送到地址之前获取交易大小

[英]Bitcoin core - How to get transaction size before send BTC to an address

How can I get transaction size before sending BTC to an external address?如何在将 BTC 发送到外部地址之前获取交易大小?

I am using Bitcoin core to make the transactions, and I was trying to calculate transaction size.我正在使用比特币核心进行交易,并且我正在尝试计算交易规模。 So that I can use it to estimate transaction fee.这样我就可以用它来估算交易费用。 But couldn't find a way却找不到办法

Could you tell me its logic and method to do it?你能告诉我它的逻辑和方法吗?

You can sign the transaction locally in your code, instead of using bitcoind .您可以在代码中本地签署交易,而不是使用bitcoind Then you simply measure the size of the transaction serialised as a byte stream.然后您只需测量序列化为字节流的事务的大小。

After signing the transaction with either与任何一方签署交易后

  • signrawtransactionwithwallet
  • signrawtransactionwithkey
  • signrawtransaction , this is deprecated and fully removed from bitcoind 0.18.0 and above. signrawtransaction ,这已被弃用并从 bitcoind 0.18.0 及更高版本中完全删除。

It will return hex value in the result.它将在结果中返回十六进制值。 Use decoderawtransaction to view your transaction before sending.在发送之前使用decoderawtransaction查看您的交易。 In the result it has 'size' attribute showing the size of your transaction.在结果中,它具有显示交易大小的“大小”属性。 Below is a snippet from bitcoind documentation.下面是来自 bitcoind 文档的片段。

...
  "txid" : "hex",           (string) The transaction id
  "hash" : "hex",           (string) The transaction hash (differs from txid for witness transactions)
  "size" : n,               (numeric) The transaction size
  "vsize" : n,              (numeric) The virtual transaction size (differs from size for witness transactions)
  "weight" : n,             (numeric) The transaction's weight (between vsize*4 - 3 and vsize*4)
 ...

However, if you are planning to broadcast a transaction with a known fee rate in mind, you should use fundrawtransaction to specify your transaction's fee rate etc.但是,如果您计划以已知的费率广播交易,您应该使用fundrawtransaction来指定您的交易费率等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM