The Bitcoin script happens to be a very powerful programming tool/language used within the Bitcoin protocol primarily for transaction purposes. Every transaction output has a locking script (ScriptPubKey) and an unlocking script that helps to unlock the output.
Script basically comprises of two things, which are: Opcodes and Data. The Opcode enables several operations on the data, while the data contains public keys and signatures.
There are several scripts used in Bitcoin for transaction purposes, which I pointed out in my previous
Thread . I saw the need to conduct my own research on how these scripts work and share my findings with others who might want to make reference to them in the future.
The following are examples of Bitcoin Scripts I listed, along with their explanations. Note that these are all standard scripts that fall under two main categories: Legacy and SegWit.
Legacy contains:
- P2PK
- P2PKH
- P2SH
- P2MS
- OP_RETURN
SegWit contains:
Starting with Legacy
P2PK P2PK stands for Pay-To-Public-Key. It is a script that locks a Bitcoin output to a public key. This pattern only allows someone to receive Bitcoin on their public key. This was the first method used for receiving Bitcoin. To unlock a P2PK, a valid signature is required in the ScriptSig.
A typical example is the transaction made in block 170, as shown below. There are two separate transactions of 1B sats and 4B sats, making a total of 5B sats. When you take a close look at the address on the left, you see a P2PK.
P2PKH P2PKH stands for Pay-To-Public-Key-Hash. Unlike P2PK which contains a public key, P2PKH contains a public key hash also known as an address. As I stated in another of my old
Thread , addresses are generated from a public key by a process called hashing. Note that P2PKH is literally the most common method used for receiving Bitcoin today. To unlock P2PKH, it requires the public key and corresponding signature. Addresses that usually begin with the prefix '1' and contain 33 to 34 characters are P2PKH addresses.
P2SH P2SH stands for Pay-To-Script-Hash. Unlike P2PKH, which produces an address by hashing a single public key, P2SH's address are created by hashing a redeem script. They usually have a prefix of '3' and contain about 34 characters.
3M2GhZW2FsMdfezHDBvjMEAZz6wkB32LMG
P2MS P2MS stands for Pay-to-Multisig. Most of us might have heard about multi-signature or maybe multi-signature wallets, where it involves more than one person signing the signature of a particular transaction. In this case, this script helps to lock Bitcoin in multiple public keys and requires at least two corresponding signatures to unlock them, or the assigned number of signature permitted to unlock them.
A general example is when a multi-signature wallet address is created for three parties, but only two parties can unlock the Bitcoin with their signatures.
Edited:
https://www.talkimg.com/images/2024/06/18/hUY5d.jpegSegWit
P2TR P2TR stands for Pay-To-Taproot. P2TR uses a form of digital signature called Schnorr, which is different from the initial ECDSA. P2TR uses the Bech32m encoding scheme and is usually around 62 characters in length. P2TR is still a very new address format that is still growing in terms of adoption.
P2WPKH P2WPKH stands for Pay-To-Witness-Public-Key-Hash. This is a script that locks an output to a public key hash. This output can only be unlocked via the witness, unlike the P2PKH that unlocks via ScriptSig.
P2WPKH was literally an upgrade to serve as a replacement for P2PKH.
P2WSH stands for Pay-To-Witness-Script-Hash. This is also part of the SegWit upgrade but serves as a replacement for P2SH. It has a greater benefit when used because it requires lower transaction fees when unlocking a P2WSH. This is clearly unlike the P2SH. Just like P2WPKH, the output of P2WSH can also be unlocked via the witness. They usually begin with 'bc1'.
bc1q34aq5drpuwy3wgl9lhup9892qp6svr8ldzyy7c
If you want to read further in details, use the reference link Reference is located at the bottom of the thread, though the images are screenshots made by me for illustrations which are not visually present in any of the reference material.
I am 100% open to correction as I still see myself as a learner. Pardon any of my error and share your personal opinion. You might want to also DOYR after reading this.
Public keys and Addresses - Are there striking similarities or difference:
https://bitcointalksearch.org/topic/m.64193874Total confusion about Scriptpubkey, Standard and non standard Transactions:
https://bitcointalksearch.org/topic/--5499658Bitcoin Scripts:
https://learnmeabitcoin.com/technical/script/#legacyP2PK:
https://learnmeabitcoin.com/technical/script/p2pk/P2PKH:
https://learnmeabitcoin.com/technical/script/p2pkh/P2MS:
https://learnmeabitcoin.com/technical/script/p2ms/P2SH:
https://learnmeabitcoin.com/technical/script/p2sh/P2WPKH:
https://learnmeabitcoin.com/technical/script/p2wpkh/P2WSH:
https://learnmeabitcoin.com/technical/script/p2wsh/P2TR:
https://thebitcoinmanual.com/articles/pay-to-taproot-p2tr/Bitcoinmagazine:
https://bitcoinmagazine.com/technical/bitcoin-address-types-compared-p2pkh-p2sh-p2wpkh-and-moreList of address prefixes:
https://en.bitcoin.it/wiki/List_of_address_prefixes