<p>Scripts are one of Bitcoin's more clever features. The most obvious way to implement a crypto-currency is to make a transfer be to a public key. To claim the transfer, you sign with the corresponding private key. This is not the way Bitcoin works.</p>

<p>When you send Bitcoins (the <em>out</em> of a transaction), you send them to a script. When you claim Bitcoins (the <em>in</em>) of a transaction) you claim them with a script. To determine if a transaction input correctly claims a transaction output, the two scripts are combined and the result is executed. If the result is <em>true</em>, then the input claims the output. The scripting language is stack-based and roughly similar to Forth.</p>

<p>The transaction input (the script trying to claim the Bitcoins) runs first. It will typically put a public key and a signature onto the stack. Then the output (the script whose Bitcoins are being claimed) runs. It will typically confirm that the public key is the correct one and that the signature signs the transaction with the corresponding private key.</p>

<p>Thus, you get the same effect as if you just specified a public key and signature, but you have the option of specifying more complex scripts. Unfortunately, this kind of simple script is pretty much the only kind of script supported right now. The original developer(s) imagined much more interesting scripts including things like contracts, multi-party signatures, and so on.</p>

<p>M of N signatures are planned. This way, you could list, say 3 public keys such that any 2 of them could claim the Bitcoins.</p>

<p>Unfortunately, some of the scripting components are feared to have security risks, so many of them are disabled currently.</p>

CC BY-SA 3.0
2011-09-04T17:21:54.873Z
Coolness. I never knew how integrated scripts were to the protocol.
ripper234
CC BY-SA 3.0
2011-09-04T17:00:55.703Z
2011-09-04T17:47:44.863Z
2011-09-04T17:47:44.863Z
David Schwartz
<p>Bitcoin protocol supports scripts. </p>

<ul>
<li>How do they work?</li>
<li>How are those implemented?</li>
<li>What are their intended usages? </li>
<li>When are they planned to be used?</li>
</ul>

CC BY-SA 3.0
2011-09-04T14:46:49.023Z
I asked this as one question, if you think it's more appropriate as separate questions let me know.
ripper234
CC BY-SA 3.0
2011-09-05T14:12:28.340Z
Related question providing script references: http://bitcoin.stackexchange.com/q/547/117
Gary
<script>
How do Scripts work?
ripper234
# How do Scripts work?

(Asked by: username_0 on 2011-09-04)

Bitcoin protocol supports scripts.

* How do they work?
* How are those implemented?
* What are their intended usages?
* When are they planned to be used?

**Tags:** script

> **Comments:**
> **username_0**: I asked this as one question, if you think it's more appropriate as separate questions let me know.  
> **username_1**: Related question providing script references: http://bitcoin.stackexchange.com/q/547/117  

---

## 1 answers

### Answer by username_2 on 2011-09-04. Score: 35 | Accepted answer

Scripts are one of Bitcoin's more clever features. The most obvious way to implement a crypto-currency is to make a transfer be to a public key. To claim the transfer, you sign with the corresponding private key. This is not the way Bitcoin works.

When you send Bitcoins (the *out* of a transaction), you send them to a script. When you claim Bitcoins (the *in*) of a transaction) you claim them with a script. To determine if a transaction input correctly claims a transaction output, the two scripts are combined and the result is executed. If the result is *true*, then the input claims the output. The scripting language is stack-based and roughly similar to Forth.

The transaction input (the script trying to claim the Bitcoins) runs first. It will typically put a public key and a signature onto the stack. Then the output (the script whose Bitcoins are being claimed) runs. It will typically confirm that the public key is the correct one and that the signature signs the transaction with the corresponding private key.

Thus, you get the same effect as if you just specified a public key and signature, but you have the option of specifying more complex scripts. Unfortunately, this kind of simple script is pretty much the only kind of script supported right now. The original developer(s) imagined much more interesting scripts including things like contracts, multi-party signatures, and so on.

M of N signatures are planned. This way, you could list, say 3 public keys such that any 2 of them could claim the Bitcoins.

Unfortunately, some of the scripting components are feared to have security risks, so many of them are disabled currently.

> **Comments:**
> **username_0**: Coolness. I never knew how integrated scripts were to the protocol.  

---

