As the title says I'm trying to extract bc1 addresses by using opcodes I've found from reading about bitcoin online. However, I cannot actually find the opcodes associated with bc1. The segwit outputs here are described as, from what I gather, not having OP codes. How can this be? Surely I'm misunderstanding something. Can anyone elaborate?
Native segwit scriptPubKeys are of the form
OP_n + <data>, so first a single number opcode followed by a push of some data (called the witness program). Specifically:
- For P2WPKH (pay to witness pubkey hash, BIP141),
OP_0followed by a push of 20 bytes. Those 20 bytes are the Hash160 of a public key. Their corresponding address format is defined by BIP173.
- For P2WSH (pay to witness script hash, BIP141),
OP_0followed by a push of 32 bytes. Those 32 bytes are the SHA256 of a script. Their corresponding address format is defined by BIP173 as well.
- For P2TR (pay to taproot, BIP341),
OP_1followed by a push of 32 bytes. Those 32 bytes are a tweaked x-only public key. Their corresponding address format is defined by BIP350.
- For future witness versions, any
OP_16followed by a push of something between 2 and 40 bytes (except
OP_1followed by 32 bytes, which is P2TR). These too have addresses associated with them in BIP350, but no semantics (yet).
In general, native segwit outputs do not contain any "active" opcodes like
OP_HASH160 or anything like that, they're just stubs that push some data. The segwit (and taproot) consensus rules know how to interpret them.
I think you may be misunderstanding how an address is constructed and where scripting opcodes fit into that. The
bc1 indicates the use of the bech32 address format for SegWit versions as defined in BIP 173 and also broken down here. The hash of the witness script (SegWit version 0) or the tweaked internal key (SegWit version 1) is included within that address. The opcodes used in the witness script or the tweak of the internal key are only revealed on spending from the address. So to view and analyze the opcodes you need to look at the transactions spending from a particular address rather than the transactions sending to a particular address.