How does ScriptPubKey know the public key of an Bitcoin address?

9

4

I am currently having a blonde moment.

The ScriptPubKey provides a hashed version of the receivers public key.

scriptPubKey OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG

However, if I give someone my bitcoin address to send me money - how does the sender retrieve my public key and then hash it? As the pubKeyHash != my bitcoin address

I am probably forgetting something very obvious - but it has had my head bambuzzled this morning.

Paddy

Posted 2014-03-11T12:19:20.927

Reputation: 91

1"pubKeyHash != my bitcoin address" You're wrong here. The address contains the public key hash, along with a version number and checksum.Tim S. 2014-03-13T20:04:24.957

Answers

8

Addresses are really just shorthands for particular scripts. The standard address type (starting with a '1' on mainnet) does in fact correspond to the exact type of script you gave above.

If you base58 decode such an address, you end up with a byte string of the form 0x00 + [20-byte hash] + [4-byte checksum]. The corresponding script is OP_DUP OP_HASH160 [20-byte hash] OP_EQUALVERIFY OP_CHECKSIG.

So, in a way, your address does contain the public key's hash.

Pieter Wuille

Posted 2014-03-11T12:19:20.927

Reputation: 54 032

I used this for a test http://lenschulwitz.com/base58 , in case it helps someone

Peter PitLock 2017-08-23T11:28:39.857

-2

The sender does not need to know your public key, only the bitcoin address you provide which can be different each time. You use the public key later to redeem the funds and send to another address.

99Percent

Posted 2014-03-11T12:19:20.927

Reputation: 11

the bitcoin address is the public key.hafnero 2014-03-13T20:11:44.647

2No, you are confusing the bitcoin address with the public key. You can create many diferrent bitcoin addresses using your public key and private key. You will need the public key to redeem the funds of the transaction.99Percent 2014-03-14T01:17:24.320