<p>If the P2SH output is already redeemed, then the transaction that spent it must have provided the redeemscript with the scriptSig in the outpoint to that P2SH output.</p>

<p>The last push of data in the scriptSig contains the whole redeemscript (<a href="https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#Specification" rel="nofollow noreferrer">https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#Specification</a>).</p>

<p>E.g. for a multi-signature the scriptSig that spends the output will be of the form:</p>

<pre><code>scriptSig: 0 [signature1] ... [signatureM] {M [pubkey1] ... [pubkeyN] N OP_CHECKMULTISIG}
</code></pre>

<p>Where everything inside <code>{...}</code> is a push of that redeemscript which you just have to extract.</p>

CC BY-SA 3.0
2017-10-30T13:05:00.837Z
2017-10-30T13:10:53.427Z
2017-10-30T13:10:53.427Z
Bjarne Magnussen
<p>What is the procedure to restore redeem script of P2SH address from a transaction sent from that address? The script is stored on the blockchain in the tx data, the question is how to extract it?</p>

CC BY-SA 3.0
2017-10-30T13:05:08.697Z
are you looking for automated process or you need to restore redeem scripts a couple of times? the second can be done with blockchain.info block-explorer
amaclin
<script><input-script>
How to restore redeem script from a spent transaction?
sasha
# How to restore redeem script from a spent transaction?

(Asked by: username_0 on 2017-10-30)

What is the procedure to restore redeem script of P2SH address from a transaction sent from that address? The script is stored on the blockchain in the tx data, the question is how to extract it?

**Tags:** script, input-script

> **Comments:**
> **username_1**: are you looking for automated process or you need to restore redeem scripts a couple of times? the second can be done with blockchain.info block-explorer  

---

## 1 answers

### Answer by username_2 on 2017-10-30. Score: 1

If the P2SH output is already redeemed, then the transaction that spent it must have provided the redeemscript with the scriptSig in the outpoint to that P2SH output.

The last push of data in the scriptSig contains the whole redeemscript (<https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#Specification>).

E.g. for a multi-signature the scriptSig that spends the output will be of the form:

```
scriptSig: 0 [signature1] ... [signatureM] {M [pubkey1] ... [pubkeyN] N OP_CHECKMULTISIG}

```

Where everything inside `{...}` is a push of that redeemscript which you just have to extract.


---

