Understanding Bitcoin’s fundrawtransaction
Command: Input Weights
When using the Bitcoin Core (BTC) CLI, specifically the fundrawtransaction
command, you’re likely trying to add custom inputs to a transaction. However, when specifying the input_weights
parameter, there seems to be an issue with finding the correct wallet outputs.
What are input weights?
Input weights refer to the amounts of Bitcoin that can be paid as fees for transactions involving the specified inputs. This is crucial in creating custom transactions where only specific outputs are being generated from other programs. The input_weights
parameter allows you to specify these fees, ensuring that your transaction has sufficient funds.
The problem with fundrawtransaction
command
When using fundrawtransaction
, the output is a Bitcoin transaction object, which includes various fields like inputs
, outputs
, and fee
. However, when searching for specific outputs from other programs in the wallet, you’ll typically find that only some of these outputs are included. This is because:
- Only specific outputs are generated: If your program generates outputs with a specific prefix or set of addresses, you won’t see them in the
inputs
field.
- Outputs may not be included due to wallet settings: Your wallet’s configuration might exclude certain outputs by default.
Finding the correct inputs
To add custom inputs to your transaction using fundrawtransaction
, you’ll need to:
- Create a new transaction: Use
gettransaction
orsendrawtransaction
to create a new, empty transaction.
- Use the
getTransactionByHash
method: Search for transactions that match your desired output addresses and amounts.
Once you’ve found the correct input, you can use it by adding its corresponding output to the transaction using the addOutput
or addInput
methods.
Sample code
Here’s an example of how you might use fundrawtransaction
to add custom inputs:
bitcoin-cli gettransaction -pid \
--tx_hash \
--from \
--out <
EOF
In this example, gettransaction
is used to find the transaction with a specific PID, hash, and sender address. The resulting output contains the necessary information for adding custom inputs.
Best practices
- Verify wallet settings: Make sure your wallet’s configuration excludes unwanted outputs or addresses.
- Use reliable sources: Search for transactions that match your desired output addresses using tools like
gettransaction
orsendrawtransaction
.
- Test and validate: Test your transaction creation to ensure it meets your requirements.
By understanding the input_weights
parameter, creating a new transaction, finding the correct inputs, and adding custom outputs, you should be able to successfully create Bitcoin transactions with specific outputs generated from other programs in your wallet.
Conclusion
In this article, we explored the fundrawtransaction
command’s input weights parameter and demonstrated how to use it to add custom inputs to Bitcoin transactions. By understanding these concepts and implementing best practices for finding correct inputs, you can create efficient and reliable Bitcoin transactions with specific outputs generated from other programs in your wallet.
Additional resources
- [Bitcoin Core documentation: Transaction objects](
- [Bitcoin Core documentation: Create a new transaction](