<p>The script is maintained by the intended recipient; he is the one responsible to keep it and not to lose it. The nodes do not store any database of the scripts.</p>

<p>The script is provided by the spender upon spending the p2sh as part of the scriptSig data. For the exact specification of how this data is structured, <a href="https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki">see BIP 16 by Gavin Andresen</a>. This allows the other nodes to validate that the script was redeemed correctly.</p>

<p>The purpose of p2sh is not to limit the data on the blockchain – that remains the same. It is, as per the BIP, to "move the responsibility for supplying the conditions to redeem a transaction from the sender of the funds to the redeemer".</p>

CC BY-SA 3.0
2016-02-18T18:31:46.590Z
Indeed, P2SH actually results in more data being included into the blockchain. However, the bulk of that data goes into the scriptSigs, which are more prune-able.
morsecoder
CC BY-SA 3.0
2016-02-18T01:44:19.883Z
2016-02-18T01:44:19.883Z
dionyziz
<p>I understand that when I'm doing a transaction, I'm locking those bitcoins to whoever provide the solution to a script that has the hash I posted. </p>

<p>But, where does the hash get written? </p>

<p>I would assume that it is not in the blockchain, since this payment system is done so we can save space. I can imagine that the nodes store a database of hashes of scripts previously written on the blockchain, so when they see a script hash, they can find the correct script for it. Another option was that the recipient would provide the script at the time of the transaction, but then the other nodes would not be able to verify the script's end result, because the script would not be on the blockchain.</p>

CC BY-SA 3.0
2016-02-21T11:37:01.253Z
Hi araqueto, I've tried to reduce your question's wall-of-text effect to make it more accessible. In the second half of your question you had been asking a bunch more questions, that were based on incorrect speculations about the first question's answer. I felt that they didn't add to your question and removed them. If you are still interested in that part of your question, please post a separate follow-up question.
Murch
<script><transaction-verification><p2sh>
Where the P2SH script gets written?
araqueto
# Where the P2SH script gets written?

(Asked by: username_0 on 2016-02-17)

I understand that when I'm doing a transaction, I'm locking those bitcoins to whoever provide the solution to a script that has the hash I posted.

But, where does the hash get written?

I would assume that it is not in the blockchain, since this payment system is done so we can save space. I can imagine that the nodes store a database of hashes of scripts previously written on the blockchain, so when they see a script hash, they can find the correct script for it. Another option was that the recipient would provide the script at the time of the transaction, but then the other nodes would not be able to verify the script's end result, because the script would not be on the blockchain.

**Tags:** script, transaction-verification, p2sh

> **Comments:**
> **username_1**: Hi username_0, I've tried to reduce your question's wall-of-text effect to make it more accessible. In the second half of your question you had been asking a bunch more questions, that were based on incorrect speculations about the first question's answer. I felt that they didn't add to your question and removed them. If you are still interested in that part of your question, please post a separate follow-up question.  

---

## 1 answers

### Answer by username_2 on 2016-02-18. Score: 8

The script is maintained by the intended recipient; he is the one responsible to keep it and not to lose it. The nodes do not store any database of the scripts.

The script is provided by the spender upon spending the p2sh as part of the scriptSig data. For the exact specification of how this data is structured, [see BIP 16 by Gavin Andresen](https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki). This allows the other nodes to validate that the script was redeemed correctly.

The purpose of p2sh is not to limit the data on the blockchain – that remains the same. It is, as per the BIP, to "move the responsibility for supplying the conditions to redeem a transaction from the sender of the funds to the redeemer".

> **Comments:**
> **username_3**: Indeed, P2SH actually results in more data being included into the blockchain. However, the bulk of that data goes into the scriptSigs, which are more prune-able.  

---

