Skip to content

Instantly share code, notes, and snippets.

@dcousens
Last active February 3, 2024 18:59
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dcousens/1d8c24d01e3f34bee453 to your computer and use it in GitHub Desktop.
Save dcousens/1d8c24d01e3f34bee453 to your computer and use it in GitHub Desktop.
Transaction / Script Templates
  • <> represents data or script
  • {} represents data that must prefixed by OP_PUSHDATA
  • [] represents multiple {}

Standard Scripts

PubKey (pay-to-pubkey / P2PK)

Address: N/A
scriptPubKey: {pubKey} OP_CHECKSIG
scriptSig: {signature}

PubKeyHash (pay-to-pubkeyhash / P2PKH)

Address: Base58(0x00 <hash160 pubKey> <checksum>)
scriptPubKey: OP_DUP OP_HASH160 {hash160(pubKey)} OP_EQUALVERIFY OP_CHECKSIG
scriptSig: {signature} {pubKey}

ScriptHash (pay-to-scripthash / P2SH)

Address: Base58(0x05 <hash160 script> <checksum>)
scriptPubKey: OP_HASH160 {hash160(scriptPubKey2)} OP_EQUAL
scriptSig: [scriptSig2 ...] {scriptPubKey2}

MultiSig (pay-to-multisig / P2MS)

Address: N/A
scriptPubKey: m [pubKeys ...] n OP_CHECKMULTISIG
scriptSig: OP_0 [signatures ...]

Witness PubKeyHash (pay-to-witness-pubkeyhash / P2WPKH)

Address: Bech32('bc' {hash160(pubKey)})
scriptPubKey: 0 {hash160(pubKey)}
scriptSig: (empty)
witness: {signature} {pubKey}

Witness ScriptHash (pay-to-witness-scripthash / P2WSH)

Address: Bech32('bc' {sha256(script)})
scriptPubKey: 0 {sha256(scriptPubKey2)}
scriptSig: (empty)
witness: [scriptSig2 ...] {scriptPubKey2}

Non-standard Scripts

OP_RETURN

Address: N/A
scriptPubKey: OP_RETURN {data}
scriptSig: N/A

Anyone-can-spend

Address: N/A
scriptPubKey: N/A
scriptSig: OP_TRUE

Transaction-puzzle

Address: N/A
scriptPubKey: OP_HASH256 {hash} OP_EQUAL
scriptSig: <data>

SIGHASH_ALL:

"I agree to put my money in, if everyone puts their money in and the outputs are this".

This is the default. It indicates that everything about the transaction is signed, everything except for the input scripts, they are blanked.

SIGHASH_NONE:

"I agree to put my money in, as long as everyone puts their money in, but I don't care what's done with the output".

The outputs are not signed and can be anything. This mode allows others to update the transaction by changing their input's sequence numbers.

SIGHASH_SINGLE:

"I agree, as long as my output is what I want; I don't care about the others".

Inputs are signed, their scripts and sequence numbers blanked. The only output that is signed is the one at the same position as the input.


SIGHASH_ANYONECANPAY:

"I agree, as long as my input is what I want".

This modifier can be combined with the above three modes. When set, only that input is signed and the other inputs can be anything.

@dcousens
Copy link
Author

dcousens commented Aug 11, 2016

mandatory <= consensus <= standard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment