mirror of
				https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
				synced 2025-10-31 02:17:24 +00:00 
			
		
		
		
	Update 4_3_Creating_a_Raw_Transaction_with_Named_Arguments.md
This commit is contained in:
		
							parent
							
								
									053c1da879
								
							
						
					
					
						commit
						a5ae98e205
					
				| @ -36,3 +36,58 @@ $ bitcoin-cli -named getbalance account="*" minconf=1 | ||||
| ## Test Out a Raw Transaction | ||||
| 
 | ||||
| Here's what all the commands for sending a raw transaction would look like with named arguments: | ||||
| ``` | ||||
| $ utxo_txid=$(bitcoin-cli listunspent | jq -r '.[0] | .txid')  | ||||
| $ utxo_vout=$(bitcoin-cli listunspent | jq -r '.[0] | .vout') | ||||
| $ recipient="n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi" | ||||
| 
 | ||||
| $  rawtxhex=$(bitcoin-cli -named createrawtransaction inputs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout' } ]''' outputs='''{ "'$recipient'": 0.7595 }''') | ||||
| $ bitcoin-cli -named decoderawtransaction hexstring=$rawtxhex  | ||||
| { | ||||
|   "txid": "f445f121085d98635f7302e641f815d1ca4ce70f0e1b03f144ad1661dc5e10e7", | ||||
|   "hash": "f445f121085d98635f7302e641f815d1ca4ce70f0e1b03f144ad1661dc5e10e7", | ||||
|   "size": 85, | ||||
|   "vsize": 85, | ||||
|   "version": 2, | ||||
|   "locktime": 0, | ||||
|   "vin": [ | ||||
|     { | ||||
|       "txid": "2b5f5798359e0e23e02764588166f222d4ce056419dec83c743b72aad171d708", | ||||
|       "vout": 1, | ||||
|       "scriptSig": { | ||||
|         "asm": "", | ||||
|         "hex": "" | ||||
|       }, | ||||
|       "sequence": 4294967295 | ||||
|     } | ||||
|   ], | ||||
|   "vout": [ | ||||
|     { | ||||
|       "value": 0.75950000, | ||||
|       "n": 0, | ||||
|       "scriptPubKey": { | ||||
|         "asm": "OP_DUP OP_HASH160 e7c1345fc8f87c68170b3aa798a956c2fe6a9eff OP_EQUALVERIFY OP_CHECKSIG", | ||||
|         "hex": "76a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88ac", | ||||
|         "reqSigs": 1, | ||||
|         "type": "pubkeyhash", | ||||
|         "addresses": [ | ||||
|           "n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi" | ||||
|         ] | ||||
|       } | ||||
|     } | ||||
|   ] | ||||
| } | ||||
| 
 | ||||
| $ signedtx=$(bitcoin-cli -named signrawtransaction hexstring=$rawtxhex | jq -r '.hex') | ||||
| $ bitcoin-cli -named sendrawtransaction hexstring=$signedtx | ||||
| 8000dca7b1e7ab70f4056bc4512af6ffff7727d1588436521da3e5d886dbcddf | ||||
| ``` | ||||
| Voila! You've sent out another raw transaction, but this time using named arguments for clarity and to reduce errors. | ||||
| 
 | ||||
| > **WARNING:** This doesn't actually seem to work at the moment. The `createrawtransaction` command gives the error "Unknown named parameter inputs", though it's definitely listed as the appropriate argument name in the help page. | ||||
| 
 | ||||
| With this lesson out of the way, we're now going to put named arguments back on the shelf. If you want to use it your own, you should; just consult the `help` info for each command to see what the arguments are called. However, this tutorial will now return to the shorter (but not necessarily more intuitive) use of ordered arguments. | ||||
| 
 | ||||
| ## Summary: Creating a Raw Transaction with Named Arguments | ||||
| 
 | ||||
| By running `bitcoin-cli` with the `-named` flag, you can use named arguments rather than depending on ordered arguments. `bitcoin-cli help` will always show you the right name for each argument. This can result in more robust, easier-to-read, less error-prone code. | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user