I am currently learning bitcoin technology. So I came up around the term raw transaction. There are many tools to create a raw transaction but I want to do it all by myself.

My Idea is to write a raw transaction and broadcast it over network without cli. All I want is to deeply understand the Bitcoin Raw transaction.

To make it simple my transaction has one input and one output. I have got all the input as follows:

#All the values entered here are for example. None need to be true.

Version: 010000
Reverse of previous Tx hash: 8602122a7044b8795b5829b6b48fb1960a124f42ab1c003e769bbaad31cb2
Previous output index: 000000
Script size: 6a
Script sig: 3044022.............................
Output Count: 01
Value(in satoshi): 1000000 //Please check if it is written in correct format or not
Script size: //To be known
scriptPubkey: //To be known
locktime: 00000000

The problem is I don't know how to generate the scriptPubKey and how to write the value in Satoshi.

The info you may need to generate scriptPubKey is:

Private Key: 94C54DFCAE5E4E64A82B21478A9A243039AA57650EC6395FEC4250ACF90C3902
Public Key: 033c6f7a45e7892df81329e453b9faf5bafef648dfd9bec321eecc8e65512b3c367

Okay don't rush to block explorer. The wallets are empty. 😉

  • Not sure if I understand your question correctly, are you looking for createrawtransaction?
    – user103136
    Jan 6, 2022 at 7:23
  • 1
    I want to know how the sriptPubKey is generated? the scriptPubKey here: medium.datadriveninvestor.com/… is very long as compared to just a ripemd160 hash of public key.
    – madhurkant
    Jan 6, 2022 at 7:29
  • It sounds like you may be working with actual funds on mainnet. I couldn't find the transaction you are referring to in your question, but you should consider doing this sort of exploratory work on testnet instead in case you're currently using actual funds.
    – Murch
    Jan 7, 2022 at 17:14

1 Answer 1


A common scriptPubKey format, known as Pay-to-Public-Key-Hash (P2PKH), has the following form:

OP_DUP OP_HASH160 <push of 20-byte public key hash> OP_EQUALVERIFY OP_CHECKSIG

The hash of the public key is formed by ripemd-160(sha-256(compressed public key)).

You can find the hex encoding of the opcodes here: https://en.bitcoin.it/wiki/Script

The amount should be encoded as 8 bytes, in little-endian format. If you want to send 1 million satoshis, this would be 0x40420F0000000000.

By the way, you are missing "Input Count: 01" and sequence number in your example transaction.

The scriptPubKey in the article you linked is:


Decoded, this is:

OP_DUP OP_HASH160 [push 20 bytes 76bc4190f3d8e2315e5c11c59cfc8be9df747e3] OP_EQUALVERIFY OP_CHECKSIG

This is exactly the same as above - a P2PKH output spending to the public key whose hash is 76bc4190f3d8e2315e5c11c59cfc8be9df74.

The article you linked is incorrect, when it says:

Locking Script — This is the hash of the locking script that specifies the conditions that must be met in order to spend this output.

It is referring to a P2SH output, but the output in the example is a P2PKH output.

  • If i write these values in a raw tx, will it be valid?
    – madhurkant
    Jan 6, 2022 at 7:17
  • Yes, all you need to do is hash the public key and put that in the script I mentioned. Jan 6, 2022 at 7:18
  • but sriptPubKey here: medium.datadriveninvestor.com/… is very different from hashing.
    – madhurkant
    Jan 6, 2022 at 7:19
  • There are many possible scriptPubKey formats. I've shown P2PKH. You can find more info on the others here: bitcoin.stackexchange.com/a/111575/51948 Jan 6, 2022 at 7:23
  • Actually, the scriptPubKey in your example is exactly the same. I've added an explanation to the bottom of my answer. Jan 6, 2022 at 7:31

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.