3

My address is 389CLh5Ect2i7U5116gqjBSLykYHRmdcgZ. In request from site i see this scriptPubKey, how i can generate this scriptPubKey from my Address {scriptPubKey: "a91446c443cc449d9e9a54a9e07a30dfd2ab1960a18f87", value: 60000} ?

If you have examples in javascript it will be good.

1 Answer 1

2

this is the partial answer, on the underlying logic. I cannot help with java script. The critical part would be the base58decoding, but it seems there are solutions already: https://www.npmjs.com/package/base58check

Underlying logic:

the scriptpubkey contains the RipeMD160 Hash, surrounded by some codes: a9 14 87. This is a P2SH address.

the meaning of the codes is:

a9 -> do a RipeMD160 on the top stack item
14 -> push hex 14 (decimal 20) bytes on stack
87 -> check if the top two stack elements are equal

From your address, you need four steps, to come to this goal:

1.) base58decode the address
2.) remove last 4 bytes (this is a checksum)
3.) remove the first two bytes (the network prefix
4.) surround the codes to it

effectivly the procedure is the revers of the standard "base58check encoding": which answers, how to come from a pubkey in hexformat to an address:

0: have a Private ECDSA Key
1: derive the Public ECDSA Key
2: do a SHA-256 of 1
3: RIPEMD-160 Hash of 2
4: add address prefix 0x00 for P2PKH, 0x05 for P2SH
5. sha256
6. another sha256
7. take first four Bytes from step 6 as checksum
8. append checksum from step 7 to the result from step4
9. encode Base58

--> your bitcoin address !

help while testing: http://gobittest.appspot.com/Address (hint: never put your production private keys into a webpage - you might/will loose the funds on it!)

2
  • scriptPubKey is static or dynamic ? Jan 8, 2018 at 3:10
  • I am not sure what you mean by static or dynamic. The pubkey is derived from the private key via the ECDSA logic, then hashed, concatenated with a prefix and chcksummed, re-assembled and bas58encoded. There are other pubkey-scripts, which can be assembled dynamically, but not keys... Jan 8, 2018 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.