mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-07 16:06:26 +00:00
wrote this chapter properly
This commit is contained in:
parent
6d553ab6fd
commit
b0076ac80a
@ -1,10 +1,8 @@
|
|||||||
> **WARNING:** This chapter is awaiting the writing of chapter 12+
|
# 10.6: Spending a P2SH Transaction
|
||||||
|
|
||||||
# 8.5: Spending a P2SH Transaction
|
|
||||||
|
|
||||||
> :information_source: **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning.
|
> :information_source: **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning.
|
||||||
|
|
||||||
Before we close out this overview of P2SH transactions, we're going to touch upon how to spend them.
|
Before we close out this overview of P2SH transactions, we're going to touch upon how to spend them. This section is mainly an overview, referring back to a previous section where we _already_ spent a P2SH transaction.
|
||||||
|
|
||||||
## Use the Redeem Script
|
## Use the Redeem Script
|
||||||
|
|
||||||
@ -12,24 +10,35 @@ As we saw in [§6.2: Spending a Transaction to a Multisig](06_2_Spending_a_Trans
|
|||||||
|
|
||||||
### Collect Your Variables
|
### Collect Your Variables
|
||||||
|
|
||||||
Because P2SH addresses aren't integrated into `bitcoin-cli` there will be no short-cuts for P2SH spending like you saw in [§6.3: Sending an Automated Multisig](6_3_Sending_an_Automated_Multisig.md). You're going to need to collect all the more complex variables on your own!
|
Because P2SH addresses other than the special multisig and nested Segwit addresses aren't integrated into `bitcoin-cli` there will be no short-cuts for P2SH spending like you saw in [§6.3: Sending an Automated Multisig](6_3_Sending_an_Automated_Multisig.md). You're going to need to collect all the more complex variables on your own!
|
||||||
|
|
||||||
[[PENDING]]
|
This means that you need to collect:
|
||||||
|
|
||||||
[[Notes: Example of saving redeemScript, recipient, keys, and scriptPubKey.]]
|
* The `hex` of the `scriptPubKey` for the transaction you're spending
|
||||||
|
* The serialized `redeemScript`
|
||||||
|
* Any private keys, since you'll be signing by hand
|
||||||
|
* All of the regular `txids`, `vouts`, and `addresses` that you'd need
|
||||||
|
|
||||||
## Create the Transaction
|
## Create the Transaction
|
||||||
|
|
||||||
[[PENDING]]
|
As we saw in §6.2, the creation of a transaction is pretty standard:
|
||||||
|
```
|
||||||
|
$ rawtxhex=$(bitcoin-cli -named createrawtransaction inputs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout' } ]''' outputs='''{ "'$recipient'": 0.00005}''')
|
||||||
|
$ echo $rawtxhex
|
||||||
|
020000000121654fa95d5a268abf96427e3292baed6c9f6d16ed9e80511070f954883864b10000000000ffffffff0188130000000000001600142c48d3401f6abed74f52df3f795c644b4398844600000000
|
||||||
|
```
|
||||||
|
However, signing requires entering extra information for the (1) `scriptPubKey`; (2) the `redeemScript`; and (3) any required private keys.
|
||||||
|
|
||||||
[Notes: I *think* this is just the same as what we did in chapter 6.2, but I need to actually receive a P2SH transaction to test it, and that requires first getting to the APIs, then using one to send myself a P2SH transaction, then writing up how to respend that.]
|
Here's the example of doing so for that P2SH-embedded multisig in §6.2:
|
||||||
|
```
|
||||||
|
$ bitcoin-cli -named signrawtransactionwithkey hexstring=$rawtxhex prevtxs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout', "scriptPubKey": "'$utxo_spk'", "redeemScript": "'$redeem_script'" } ]''' privkeys='["cNPhhGjatADfhLD5gLfrR2JZKDE99Mn26NCbERsvnr24B3PcSbtR"]'
|
||||||
|
```
|
||||||
|
With any other sort of P2SH you're going to be including a different `redeemscript`, but otherwise the practice is exactly the same. The only difference is that after two chapters of work on Scripts you now understand what the `scriptPubKey` is and what the `redeemScript` is, so hopefully what were mysterious elements four chapters ago are now old hat.
|
||||||
|
|
||||||
## Summary: Spending a Transaction with a Bitcoin Script
|
## Summary: Spending a Transaction with a Bitcoin Script
|
||||||
|
|
||||||
[[PENDING]]
|
You already spent a P2SH back in Chapter 6, when you resent a multsig transaction the hard way, which required lining up the `scriptPubKey` and `redeemScript` information. Now you know that the `scriptPubKey` is a standardized P2SH locking script, while the `redeemScript` matches a hash in that locking script and that you need to be able to run it with the proper variables to receive a `True` result. But other than knowing more, there's nothing new in spending a P2SH transaction, because you already did it!
|
||||||
|
|
||||||
[Notes: Say it's just like respending that multisig, the hard way]
|
|
||||||
|
|
||||||
## What's Next?
|
## What's Next?
|
||||||
|
|
||||||
Advance through "Bitcoin Scripting" with [Chapter Nine: Empowering Timelock with Bitcoin Scripts](09_0_Empowering_Timelock_with_Bitcoin_Scripts.md).
|
Advance through "Bitcoin Scripting" with [Chapter Eleven: Empowering Timelock with Bitcoin Scripts](11_0_Empowering_Timelock_with_Bitcoin_Scripts.md).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user