Bitcoin: What’s the “weight” meaning in fundrawtransaction cmd’s input_weights parameter

Here is an article based on your request:

Understanding Bitcoin inputs and output_weights parameters in fundrawtransaction

When using the bitcoin-cli command line tool, you may encounter problems when trying to add entries to a transaction with certain entries from your wallet. In this article, we will consider what the weights parameter does in fundrawtransaction and how to use it effectively.

What are inputs and output_weights?

In Bitcoin, an input is a hash of a script that indicates what output this input will be spent on. The output weight is the amount of coins or a second asset that is transferred to the corresponding address.

When using bitcoin-cli fundrawtransaction, you can specify inputs for your transaction by specifying them as command line arguments in the format: . The hash of the script is a unique identifier for the input script, and the sum is the value of the output that this input will be spent on.

For example:

bitcoin-cli fundrawtransaction -txid 1234567890abcdef

This will create a transaction with the input of the specified hash of the script and spend `X'' units of coins (represented by the amount) on this output.

What isoutput_weights?

In Bitcoin, inputs are considered "weighted" because each input is associated with several outputs. Each output weight represents how many coins or assets will be transferred to its corresponding address for that input. In other words, an input with a high output weight means that you can spend more coins on that output.

When usingbitcoin-cli fundrawtransaction, theoutput_weightsparameter specifies the weight of each output used in the transaction. If there are multiple outputs associated with an input, you will need to specify the output weights for those inputs accordingly.

How ​​to useinput_weights

To add inputs with specific outputs generated from your wallet, you can use theinput_weightsparameter along with theinputscommand line argument.

bitcoin-cli input-weights

For example:

bitcoin-cli input-weights Address my_wallet 1000000 2

This will indicate that you want to spend at least Xunits of coins on the first exit and use weightYfor that exit.

Usage Example

Suppose you have a wallet with an address called "MyWallet" and it has two outputs: output A (1 BTC) and output B (5 BTC). You want to spend 10 BTC from your wallet on output A using the script hash :

bitcoin-cli fundrawtransaction -txid 1234567890abcdef MyWallet 2

The output will be a transaction with inputs and outputs specified in the above format. To add an input for this transaction, you can use input-weightsalong with thefundrawtransactioncommand:

bitcoin-cli fundrawtransaction -txid 1234567890abcdef MyWallet input-weights MyWallet Address 10 2

This will indicate that you want to spend at least 10 coins per output A (1 BTC) using your wallet address.

I hope this article will help clarify the parameter input_weightsinfundrawtransaction`. Let me know if you have any additional questions or need additional assistance.

Leave a Comment

Your email address will not be published. Required fields are marked *