<blockquote>
<p>What is transaction matching?</p>
</blockquote>
<p>When a wallet implementation is trying to figure out how to sign a script, it needs to figure out whether it's a script it <em>knows</em> how to sign for first. This can be very simple (e.g. only supporting P2PKH and P2WPKH spending), more complicated (e.g. spending a multisig output which needs gathering signatures from co-signers), or arbitrarily complex, depending on what the software is doing.</p>
<p>One approach for doing that is having a number of built-in &quot;templates&quot;, which are not real scripts, but just patterns to match against. As an analogy, think of the word &quot;telecommunication&quot; matching the pattern &quot;tel????muni??ion&quot;, where &quot;?&quot; means any letter. &quot;tel????muni??ion&quot; itself is not a word, but it can be used to match against words.</p>
<p>In a similar vein, a &quot;script template&quot; <code>OP_DUP OP_HASH160 OP_PUBKEYHASH OP_EQUALVERIFY OP_CHECKSIG</code> could be used to match P2PKH outputs. &quot;OP_PUBKEYHASH&quot; doesn't actually exist, it's just a placeholder for &quot;anything that looks like a public key hash&quot;, just like &quot;?&quot; is not a letter but can be used to match against any letter.</p>
<blockquote>
<p>How might these codes be used in practice?</p>
</blockquote>
<p>Not.</p>
<p>It's an implementation detail used internally in some software, and not something you should know or care about as a user. In fact, Bitcoin Core since version 0.17.0 (released in October 2018) doesn't use this style of matching anymore, but an alternate approach that does not use templates or pseudo-opcodes.</p>

CC BY-SA 4.0
2024-04-26T22:00:55.853Z
2024-04-26T22:15:39.743Z
2024-04-26T22:15:39.743Z
Pieter Wuille
<p>I see the following on <a href="https://en.bitcoin.it/wiki/Script#Pseudo-words" rel="nofollow noreferrer">bitcoin.it</a>:</p>
<hr />
<p><strong>Pseudo-words</strong></p>
<p>These words are used internally for assisting with transaction matching. They are invalid if used in actual scripts.</p>
<div class="s-table-container"><table class="s-table">
<thead>
<tr>
<th>Word</th>
<th>Opcode</th>
<th>Hex</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>OP_PUBKEYHASH</td>
<td>253</td>
<td>0xfd</td>
<td>Represents a public key hashed with OP_HASH160.</td>
</tr>
<tr>
<td>OP_PUBKEY</td>
<td>254</td>
<td>0xfe</td>
<td>Represents a public key compatible with OP_CHECKSIG.</td>
</tr>
<tr>
<td>OP_INVALIDOPCODE</td>
<td>255</td>
<td>0xff</td>
<td>Matches any opcode that is not yet assigned.</td>
</tr>
</tbody>
</table></div>
<hr />
<p>What is transaction matching?</p>
<p>How might these codes be used in practice?</p>

CC BY-SA 4.0
2024-04-26T22:26:13.450Z
I've edited the bitcoin.it page to drop the mention of these. They're confusing, outdated, and IMHO should never have been mentioned on that page to begin with as they were just an implementation detail and not part of the Bitcoin protocol. See my answer for why.
Pieter Wuille
<transactions><script>
What is an example usage for Script pseudo words?
Lee
# What is an example usage for Script pseudo words?

(Asked by: username_0 on 2024-04-26)

I see the following on [bitcoin.it](https://en.bitcoin.it/wiki/Script#Pseudo-words):

---

**Pseudo-words**

These words are used internally for assisting with transaction matching. They are invalid if used in actual scripts.

| Word | Opcode | Hex | Description |
| --- | --- | --- | --- |
| OP\_PUBKEYHASH | 253 | 0xfd | Represents a public key hashed with OP\_HASH160. |
| OP\_PUBKEY | 254 | 0xfe | Represents a public key compatible with OP\_CHECKSIG. |
| OP\_INVALIDOPCODE | 255 | 0xff | Matches any opcode that is not yet assigned. |

---

What is transaction matching?

How might these codes be used in practice?

**Tags:** transactions, script

> **Comments:**
> **username_1**: I've edited the bitcoin.it page to drop the mention of these. They're confusing, outdated, and IMHO should never have been mentioned on that page to begin with as they were just an implementation detail and not part of the Bitcoin protocol. See my answer for why.  

---

## 1 answers

### Answer by username_1 on 2024-04-26. Score: 2 | Accepted answer

> What is transaction matching?

When a wallet implementation is trying to figure out how to sign a script, it needs to figure out whether it's a script it *knows* how to sign for first. This can be very simple (e.g. only supporting P2PKH and P2WPKH spending), more complicated (e.g. spending a multisig output which needs gathering signatures from co-signers), or arbitrarily complex, depending on what the software is doing.

One approach for doing that is having a number of built-in "templates", which are not real scripts, but just patterns to match against. As an analogy, think of the word "telecommunication" matching the pattern "tel????muni??ion", where "?" means any letter. "tel????muni??ion" itself is not a word, but it can be used to match against words.

In a similar vein, a "script template" `OP_DUP OP_HASH160 OP_PUBKEYHASH OP_EQUALVERIFY OP_CHECKSIG` could be used to match P2PKH outputs. "OP\_PUBKEYHASH" doesn't actually exist, it's just a placeholder for "anything that looks like a public key hash", just like "?" is not a letter but can be used to match against any letter.

> How might these codes be used in practice?

Not.

It's an implementation detail used internally in some software, and not something you should know or care about as a user. In fact, Bitcoin Core since version 0.17.0 (released in October 2018) doesn't use this style of matching anymore, but an alternate approach that does not use templates or pseudo-opcodes.


---

