Bitcoin Transactions, Pay-To-Public-Key-Hash Discussion

Before we use a UTXO as an input we must run the unlocking script to verify we are authorized to us the UTXO, then we add a new locking script for the next user to prove they are authorized prior to them using it.

Is the above statement accurate?

Also, if we are using 3 UTXO’s to send to someone. Does that person receive it as 1 new UTXO or do they receive it as 3 UTXO’s?

Summary of the Section:

Pay to Public Key Hash (P2PKH)

Bitcoin Transactions are made of input and output…

UTXOs (unspent transaction outputs). A Bitcoin Wallet reads the blockchain for UTXOs attached to the public key. Sum of those UTXOs in your wallet is the balance you own.

Locking Script (Scriptpubkey) is a piece of code that is embedded in every bitcoin transaction and only Unlocking Script (ScriptSig) can unlock this script. This mechanism helps the network to validate the transactions.

Combining Locking Script and Unlocking Script to validate

Bitcoin uses the hexadecimal to represent code, functions etc so knowing the basics of it is important.

Serialization. Is the process of converting data into something that can easily transmit over the network. All bitcoin transactions are serialized. What we see usually on Blockchian explorer is transaction data represented in JSON format for us humans to read easily.

1 Like

Yes.

The person receive is as 1 UTXO. it will be one output if all are sending to one address.

2 Likes

Is the locking script and the unlocking script have anything to do with public keys and private keys?

1 Like

Yes, for locking or unlocking scripts are related closely to both processes.

A quick example: (from the one of the next lessons)

Locking Script without segwit
OP_DUP OP_HASH160 <PK_HASH> OP_EQUALVERIFY OP_CHECKSIG
With Segwit
0<PK_HASH>

Unlocking Script without segwit
<PUB_KEY>
With Segwit
<PUB_KEY> (in witness data structure)

So PK_HASH goes for the hash of public key hash.
<PUB_KEY> for the public key.

Carlos Z

2 Likes

I have faced the issue with the Bitcoin IDE bug. I follow step by step your example but I kept having a different value. I tried with other transaction that randomly took from the blockchain and the same unsuccesful results. You recommend instead to use https://github.com/kallewoof/btcdeb but I wonder if I can use Python to try these experiments. I search a little bit and there’s a library called base58. Does any Python programmer taking this course ever tried this library?

base58 is just the encoding library and it should work the same in any language. You should be able to make a multisig tx in any language as well if you wish. But you would be a bit on your own and I will have more trouble helping you in case something goes wrong.

There is a bitcoinlib for python (https://pypi.org/project/bitcoinlib/) you can use. And you can get more examples in the Mastering Bitcoin book which uses Python in its examples. :slight_smile:

1 Like

Hello. I have 2 questions.

  1. When creating the unlocking script. How does a recipient know the signature that their sender has produced? Does the sender send the signature to the recipient but off-chain?

  2. How does a sender know the public key of their recipient? Because usually, when I send crypto to a wallet, I only the address, not the public key. Unlike private key => public key, is it possible to go from address => public key?

1 Like

@Filip good day from here sir, please i don’t really understand Pay to Pubkey Hash, you stammered whole explaining, and perhaps minced some words, so please can you explain better sir, thank you, I’d really appreciate a reply to this☺️

@filip loving the course, could i ask if the pdf of your slides was ever updated ? I’ve just looked and could not find the pdf, would be very helpful :grinning:

@filip

I realise the course was recorded some time ago. However would it be possible to upload the powerpoint presentations here on the forum please? Or PDF or E-pub.

Specifically : Raw transactions & serialisation presentation + Transaction script walkthrough & execution lectures.

I think this can come in handy to analyse it better. I got it, but it would be easier to watch video, and then analyse the document without explanation.

Thanks in advance :slight_smile:

¿What is the mathematical relationship between the signature and public key that is verify through CHECKSIG Opcode?

Dear Filip,

I am trying to run some pay to pub key hash transaction to get familirized with bitcoin scripting.
For example : https://www.blockchain.com/explorer/transactions/btc/49526e4a95d86abf6403215c470cc042c36c216bd04c825d77923fc707229e0f

I tried the paste the followings onto https://siminchen.github.io/bitcoinIDE/build/editor.html
But the execution was unsuccessful.
Any Idea why?

script executed:
30440220515c272c51cdfda741e0313bbbd97f8b5989169052f85b0916c9d7fce19375ab0220099584b5de743bf81d0e76c6975cb0223ef3f04c84fadd12dce25a3b6102579801 0369e03e2c91f0badec46c9c903d9e9edae67c167b9ef9b550356ee791c9a40896 OP_DUP OP_HASH160 9f21a07a0c7c3cf65a51f586051395762267cdaf OP_EQUALVERIFY OP_CHECKSIG

It seems that the hash of the pub key doesnt match the hash value expected.

In regards to the locking script video ,

Is f1304d590d…f68ea81 a public address in this transaction?