mirror of
				https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
				synced 2025-10-31 02:17:24 +00:00 
			
		
		
		
	corrected examples (note: getaddressinfo), re-redited
This commit is contained in:
		
							parent
							
								
									11e1676695
								
							
						
					
					
						commit
						6272f00904
					
				| @ -10,7 +10,7 @@ The methodology for automated raw transactions is simple: you create a raw trans | |||||||
| 
 | 
 | ||||||
| In order to use this command, you'll need to ensure that your ~/.bitcoin/bitcoin.conf file contains rational variables for calculating transaction fees. Please see [§4.1: Sending Coins The Easy Way](04_1_Sending_Coins_The_Easy_Way.md) for more information on this. | In order to use this command, you'll need to ensure that your ~/.bitcoin/bitcoin.conf file contains rational variables for calculating transaction fees. Please see [§4.1: Sending Coins The Easy Way](04_1_Sending_Coins_The_Easy_Way.md) for more information on this. | ||||||
| 
 | 
 | ||||||
| For very conservative numbers, we suggested adding the following to the bitcoin.conf: | For very conservative numbers, we suggested adding the following to the `bitcoin.conf`: | ||||||
| ``` | ``` | ||||||
| mintxfee=0.0001 | mintxfee=0.0001 | ||||||
| txconfirmtarget=6 | txconfirmtarget=6 | ||||||
| @ -23,9 +23,10 @@ txconfirmtarget=1 | |||||||
| 
 | 
 | ||||||
| ## Create a Bare Bones Raw Transaction | ## Create a Bare Bones Raw Transaction | ||||||
| 
 | 
 | ||||||
| To use `fundrawtransaction` you first need to create a bare-bones raw transaction that lists _no_ inputs and _no_ change address. You'll just list your recipient and how much you want to send them: | To use `fundrawtransaction` you first need to create a bare-bones raw transaction that lists _no_ inputs and _no_ change address. You'll just list your recipient and how much you want to send them, in this case `$recipient` and `0.0002` BTC. | ||||||
| ``` | ``` | ||||||
| $ unfinishedtx=$(bitcoin-cli -named createrawtransaction inputs='''[]''' outputs='''{ "'$recipient'": 1.0 }''') | $ recipient=n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi | ||||||
|  | $ unfinishedtx=$(bitcoin-cli -named createrawtransaction inputs='''[]''' outputs='''{ "'$recipient'": 0.0002 }''') | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ## Fund Your Bare Bones Transaction | ## Fund Your Bare Bones Transaction | ||||||
| @ -34,9 +35,9 @@ You then tell `bitcoin-cli` to fund that bare-bones transaction: | |||||||
| ``` | ``` | ||||||
| $ bitcoin-cli -named fundrawtransaction hexstring=$unfinishedtx | $ bitcoin-cli -named fundrawtransaction hexstring=$unfinishedtx | ||||||
| { | { | ||||||
|   "hex": "020000000169847669938c6a66ef790b87ebb6233059609bee4601476c5948db1a4defc9690100000000feffffff02a8e30f05000000001976a914a6f0ee37c44947f4137d56e4aab12f27ad50369188ac00e1f505000000001976a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88ac00000000", |   "hex": "02000000012db87641c6a21e5a68b20c226428544978e6ac44964d5d8060d7388000c584eb0100000000feffffff02204e0000000000001976a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88ac781e0000000000001600140cc9cdcf45d4ea17f5227a7ead52367aad10a88400000000", | ||||||
|   "changepos": 0, |   "fee": 0.00022200, | ||||||
|   "fee": 0.00022600 |   "changepos": 1 | ||||||
| } | } | ||||||
| ``` | ``` | ||||||
| That provides a lot of useful information, but once you're confident with how it works, you'll want to use JQ to save your hex to a variable, as usual: | That provides a lot of useful information, but once you're confident with how it works, you'll want to use JQ to save your hex to a variable, as usual: | ||||||
| @ -51,15 +52,16 @@ Running `decoderawtransaction` will show that the raw transaction is now laid ou | |||||||
| ``` | ``` | ||||||
| $ bitcoin-cli -named decoderawtransaction hexstring=$rawtxhex3 | $ bitcoin-cli -named decoderawtransaction hexstring=$rawtxhex3 | ||||||
| { | { | ||||||
|   "txid": "2e34603b7449d29412fb7b0d184085d4d839d965f2bba361749c20d9dbae3d0b", |   "txid": "b3b4c2057dbfbef6690e975ede92fde805ddea13c730f58401939a52c9ac1b99", | ||||||
|   "hash": "2e34603b7449d29412fb7b0d184085d4d839d965f2bba361749c20d9dbae3d0b", |   "hash": "b3b4c2057dbfbef6690e975ede92fde805ddea13c730f58401939a52c9ac1b99", | ||||||
|   "size": 119, |  | ||||||
|   "vsize": 119, |  | ||||||
|   "version": 2, |   "version": 2, | ||||||
|  |   "size": 116, | ||||||
|  |   "vsize": 116, | ||||||
|  |   "weight": 464, | ||||||
|   "locktime": 0, |   "locktime": 0, | ||||||
|   "vin": [ |   "vin": [ | ||||||
|     { |     { | ||||||
|       "txid": "69c9ef4d1adb48596c470146ee9b60593023b6eb870b79ef666a8c9369768469", |       "txid": "eb84c5008038d760805d4d9644ace67849542864220cb2685a1ea2c64176b82d", | ||||||
|       "vout": 1, |       "vout": 1, | ||||||
|       "scriptSig": { |       "scriptSig": { | ||||||
|         "asm": "", |         "asm": "", | ||||||
| @ -70,21 +72,8 @@ $ bitcoin-cli -named decoderawtransaction hexstring=$rawtxhex3 | |||||||
|   ], |   ], | ||||||
|   "vout": [ |   "vout": [ | ||||||
|     { |     { | ||||||
|       "value": 0.84927400, |       "value": 0.00020000, | ||||||
|       "n": 0, |       "n": 0, | ||||||
|       "scriptPubKey": { |  | ||||||
|         "asm": "OP_DUP OP_HASH160 123cd8796558d195e52137ce3800e5f8120ee46f OP_EQUALVERIFY OP_CHECKSIG", |  | ||||||
|         "hex": "76a914123cd8796558d195e52137ce3800e5f8120ee46f88ac", |  | ||||||
|         "reqSigs": 1, |  | ||||||
|         "type": "pubkeyhash", |  | ||||||
|         "addresses": [ |  | ||||||
|           "mhBPM8hU2PHjDTUvwa3SC7pqv8ExkK6mH8" |  | ||||||
|         ] |  | ||||||
|       } |  | ||||||
|     },  |  | ||||||
|     { |  | ||||||
|       "value": 1.00000000, |  | ||||||
|       "n": 1, |  | ||||||
|       "scriptPubKey": { |       "scriptPubKey": { | ||||||
|         "asm": "OP_DUP OP_HASH160 e7c1345fc8f87c68170b3aa798a956c2fe6a9eff OP_EQUALVERIFY OP_CHECKSIG", |         "asm": "OP_DUP OP_HASH160 e7c1345fc8f87c68170b3aa798a956c2fe6a9eff OP_EQUALVERIFY OP_CHECKSIG", | ||||||
|         "hex": "76a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88ac", |         "hex": "76a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88ac", | ||||||
| @ -94,30 +83,50 @@ $ bitcoin-cli -named decoderawtransaction hexstring=$rawtxhex3 | |||||||
|           "n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi" |           "n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi" | ||||||
|         ] |         ] | ||||||
|       } |       } | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       "value": 0.00007800, | ||||||
|  |       "n": 1, | ||||||
|  |       "scriptPubKey": { | ||||||
|  |         "asm": "0 a782f4c6e1e75a5b24f3d675d6f11b5ebf3b2142", | ||||||
|  |         "hex": "0014a782f4c6e1e75a5b24f3d675d6f11b5ebf3b2142", | ||||||
|  |         "reqSigs": 1, | ||||||
|  |         "type": "witness_v0_keyhash", | ||||||
|  |         "addresses": [ | ||||||
|  |           "tb1q57p0f3hpuad9kf8n6e6adugmt6lnkg2zzr592r" | ||||||
|  |         ] | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|   ] |   ] | ||||||
| } | } | ||||||
| ``` | ``` | ||||||
| We saw the fee in the more extensive output, before we saved the hex to a variable with JQ, but you can verify it with the `btctxfee` JQ alias created in the [JQ Interlude](https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/blob/master/04_2__Interlude_Using_JQ.md): | We saw the fee in the more extensive output, before we saved the hex to a variable with JQ, but you can verify it with the `txfee-calc.sh` JQ script created in the [JQ Interlude](https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/blob/master/04_2__Interlude_Using_JQ.md): | ||||||
| ``` | ``` | ||||||
| $ btctxfee $rawtxhex3 | $ ~/txfee-calc.sh $rawtxhex3 | ||||||
| .00023 | .000222 | ||||||
| ``` | ``` | ||||||
| Finally, you can use `validateaddress` to see that the generated change address really belongs to you: | Finally, you can use `getaddressinfo` to see that the generated change address really belongs to you: | ||||||
| ``` | ``` | ||||||
| $ bitcoin-cli -named validateaddress address=mhBPM8hU2PHjDTUvwa3SC7pqv8ExkK6mH8 | $ bitcoin-cli -named getaddressinfo address=tb1q57p0f3hpuad9kf8n6e6adugmt6lnkg2zzr592r | ||||||
| { | { | ||||||
|   "isvalid": true, |   "address": "tb1q57p0f3hpuad9kf8n6e6adugmt6lnkg2zzr592r", | ||||||
|   "address": "mhBPM8hU2PHjDTUvwa3SC7pqv8ExkK6mH8", |   "scriptPubKey": "0014a782f4c6e1e75a5b24f3d675d6f11b5ebf3b2142", | ||||||
|   "scriptPubKey": "76a914123cd8796558d195e52137ce3800e5f8120ee46f88ac", |  | ||||||
|   "ismine": true, |   "ismine": true, | ||||||
|  |   "solvable": true, | ||||||
|  |   "desc": "wpkh([d6043800/0'/1'/10']038a2702938e548eaec28feb92c7e4722042cfd1ea16bec9fc274640dc5be05ec5)#zpv26nar", | ||||||
|   "iswatchonly": false, |   "iswatchonly": false, | ||||||
|   "isscript": false, |   "isscript": false, | ||||||
|   "pubkey": "029045eaa55d283526c723e6d5495d9b3f077b545563f86465aafcd9bfdd50359e",Y |   "iswitness": true, | ||||||
|   "iscompressed": true, |   "witness_version": 0, | ||||||
|   "timestamp": 1489170694, |   "witness_program": "a782f4c6e1e75a5b24f3d675d6f11b5ebf3b2142", | ||||||
|   "hdkeypath": "m/0'/0'/11'", |   "pubkey": "038a2702938e548eaec28feb92c7e4722042cfd1ea16bec9fc274640dc5be05ec5", | ||||||
|   "hdmasterkeyid": "144a68bde927a1fed7c2b71ad9010b0201819be5" |   "ischange": true, | ||||||
|  |   "timestamp": 1592335137, | ||||||
|  |   "hdkeypath": "m/0'/1'/10'", | ||||||
|  |   "hdseedid": "fdea8e2630f00d29a9d6ff2af7bf5b358d061078", | ||||||
|  |   "hdmasterfingerprint": "d6043800", | ||||||
|  |   "labels": [ | ||||||
|  |   ] | ||||||
| } | } | ||||||
| ``` | ``` | ||||||
| Note the `ismine` results. | Note the `ismine` results. | ||||||
| @ -128,20 +137,23 @@ At this point you can sign and send the transaction as usual. | |||||||
| ``` | ``` | ||||||
| $ signedtx3=$(bitcoin-cli -named signrawtransactionwithwallet hexstring=$rawtxhex3 | jq -r '.hex') | $ signedtx3=$(bitcoin-cli -named signrawtransactionwithwallet hexstring=$rawtxhex3 | jq -r '.hex') | ||||||
| $ bitcoin-cli -named sendrawtransaction hexstring=$signedtx3 | $ bitcoin-cli -named sendrawtransaction hexstring=$signedtx3 | ||||||
|  | 8b9dd66c999966462a3d88d6ac9405d09e2aa409c0aa830bdd08dbcbd34a36fa | ||||||
| ``` | ``` | ||||||
| In several minutes, you'll have your change back: | In several minutes, you'll have your change back: | ||||||
| ``` | ``` | ||||||
| $ bitcoin-cli listunspent | $ bitcoin-cli listunspent | ||||||
| [ | [ | ||||||
|   { |   { | ||||||
|     "txid": "37698ad6e7f62df07c2fbc549339aa680a7fa18328d7ad14ecb72b21c505cbc6", |     "txid": "8b9dd66c999966462a3d88d6ac9405d09e2aa409c0aa830bdd08dbcbd34a36fa", | ||||||
|     "vout": 0, |     "vout": 1, | ||||||
|     "address": "mhBPM8hU2PHjDTUvwa3SC7pqv8ExkK6mH8", |     "address": "tb1q57p0f3hpuad9kf8n6e6adugmt6lnkg2zzr592r", | ||||||
|     "scriptPubKey": "76a914123cd8796558d195e52137ce3800e5f8120ee46f88ac", |     "scriptPubKey": "0014a782f4c6e1e75a5b24f3d675d6f11b5ebf3b2142", | ||||||
|     "amount": 0.84927400, |     "amount": 0.00007800, | ||||||
|     "confirmations": 1, |     "confirmations": 1, | ||||||
|     "spendable": true, |     "spendable": true, | ||||||
|     "solvable": true |     "solvable": true, | ||||||
|  |     "desc": "wpkh([d6043800/0'/1'/10']038a2702938e548eaec28feb92c7e4722042cfd1ea16bec9fc274640dc5be05ec5)#zpv26nar", | ||||||
|  |     "safe": true | ||||||
|   } |   } | ||||||
| ] | ] | ||||||
| ``` | ``` | ||||||
| @ -158,4 +170,5 @@ If you must send funds with raw transactions then `fundrawtransaction` gives you | |||||||
| 
 | 
 | ||||||
| ## What's Next? | ## What's Next? | ||||||
| 
 | 
 | ||||||
| Advance through "bitcoin-cli" with [Chapter Five: Controlling Bitcoin Transactions](05_0_Controlling_Bitcoin_Transactions.md). | Complete your "Sending of Bitcoin Transactions" with [§4.6: Creating a Segwit Transaction](04_6_Creating_a_Segwit_Transaction.md). | ||||||
|  | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user