Update 4_3_Creating_a_Raw_Transaction_with_Named_Arguments.md

This commit is contained in:
Shannon Appelcline 2017-04-05 10:39:15 -07:00 committed by GitHub
parent d9ab35668c
commit f482808b9f

View File

@ -12,30 +12,30 @@ To use a named argument you must run `bitcoin-cli` with the `-named` argument. I
``` ```
alias bitcoin-cli="bitcoin-cli -named" alias bitcoin-cli="bitcoin-cli -named"
``` ```
As usual, that's for your ease of use, but we'll continue using the whole commands, to maintain clarity. As usual, that's for your ease of use, but we'll continue using the whole commands to maintain clarity.
## Test Out a Named Argument ## Test Out a Named Argument
To learn what the names are for the arguments of a command, just look at `bitcoin-cli help`. It will list the arguments in their proper order, but will now also give names for each of them. To learn what the names are for the arguments of a command, consult `bitcoin-cli help`. It will list the arguments in their proper order, but will now also give names for each of them.
For example, `bitcoin-cli getbalance` lists the following arguments: For example, `bitcoin-cli help getbalance` lists these arguments:
1. account 1. account
2. minconf 2. minconf
3. include watchonly 3. include watchonly
The following shows a traditional, unintuitive usage of `getbalance` with `minconf`: The following shows a traditional, unintuitive usage of `getbalance` using the minimum confirmation argument:
``` ```
$ bitcoin-cli getbalance "*" 1 $ bitcoin-cli getbalance "*" 1
``` ```
With named arguments you can now call it like this, which improves clarities and minimizes mistakes: With named arguments, you can clarify what you're doing, which also minimizes mistakes:
``` ```
$ bitcoin-cli -named getbalance account="*" minconf=1 $ bitcoin-cli -named getbalance account="*" minconf=1
``` ```
## Test Out a Raw Transaction ## Test Out a Raw Transaction
Here's what all the commands for sending a raw transaction would look like with named arguments: Here's what the commands for sending a raw transaction would look like with named arguments:
``` ```
$ utxo_txid=$(bitcoin-cli listunspent | jq -r '.[0] | .txid') $ utxo_txid=$(bitcoin-cli listunspent | jq -r '.[0] | .txid')
$ utxo_vout=$(bitcoin-cli listunspent | jq -r '.[0] | .vout') $ utxo_vout=$(bitcoin-cli listunspent | jq -r '.[0] | .vout')
@ -84,7 +84,7 @@ $ bitcoin-cli -named sendrawtransaction hexstring=$signedtx
``` ```
Voila! You've sent out another raw transaction, but this time using named arguments for clarity and to reduce errors. Voila! You've sent out another raw transaction, but this time using named arguments for clarity and to reduce errors.
> **WARNING:** There was a bug in Bitcoin Core 0.14, where the 'inputs' argument for 'createrawtransaction' was misnamed 'transactions'. It should be fixed in future version of Bitcoin Core. If you're using 0.14, you'll need to substitute 'transactions' for 'inputs' in the above example, but otherwise it should work as written. > **WARNING:** There is a bug in Bitcoin Core 0.14: the 'inputs' argument for 'createrawtransaction' is misnamed 'transactions'. It should be fixed in future version of Bitcoin Core. If you're using 0.14, you'll need to substitute 'transactions' for 'inputs' in the above example, but otherwise it should work as written.
## Summary: Creating a Raw Transaction with Named Arguments ## Summary: Creating a Raw Transaction with Named Arguments