<blockquote>
<p>One part of coinbase transaction is p2pkh ScriptPubKey (according to the book i read).</p>
</blockquote>
<p>That is (or at least, was) commonly the case, but there is no such requirement.</p>
<blockquote>
<p>Suppose i have all the data needed to build coinbase transaction (version,output,ect) except the p2pkh ScriptPubKey , and i have my address that i generate using bitcoin rpc getnewaddress , how do i generate the p2pkh ScriptPubKey ?</p>
</blockquote>
<p>The coinbase transaction needs to have one or more outputs, which distribute the subsidy and fees gained to the miner(s). The miner can decide to pay out thenselves in whatever way they want. In that sense, the transaction outputs of the coinbase transaction are no different from those of any other output.</p>
<p>Now, most wallets want to be paid using one of the standard output types (P2PKH, P2SH, P2WPKH; there are a few more but that doesn't matter here). Each has a corresponding address type, so if you want the payout to such an address, you just need a way to compute the corresponding scriptPubKey. This is a very standard operation, implemented in pretty much any Bitcoin software library, and literally every wallet.</p>
<p>For P2PKH specifically, there are plenty of questions on how to do that on this site. For P2SH, refer to BIP13. For P2WPKH, see BIP141.</p>
<blockquote>
<p>Extra question : when i generate new address using bitcoin rpc getnewaddress , is the generated address a public key or private key ?</p>
</blockquote>
<p>Modern wallets won't generate P2PKH addresses anymore; they are legacy. But the same applies for other address types.</p>
<p>In general, first the private key is generated (usually deterministically using BIP32). Then the corresponding public key is computed. Then that public key is hashed, and the hash is encoded as an address (for P2PKH or P2WPKH; for P2SH or P2WSH a script is involved as well).</p>

CC BY-SA 4.0
2021-10-03T01:39:04.767Z
wow i'm amazed how bitcoin has changed so much that the book i read probably obsolete now . How did you know all of this ? is there any book / documentation you can recommend me to understand this and other aspect of bitcoin ?
user6668201
CC BY-SA 4.0
2021-10-03T01:58:03.583Z
It's not that the book sounds obsolete - it sounds more like it has always been misleading if it claims coinbase always have a P2PKH output. I'm not sure about books, but all big protocol/standard changes since ~2012 or so is described in BIPs. It sounds like you're trying to write mining software for some purpose; I suggest you look through the relevant BIPs (at least 13, 16, 141, 173, 350), and perhaps study other mining software implementations.
Pieter Wuille
CC BY-SA 4.0
2021-10-03T01:58:15.253Z
And I know because it is my job.
Pieter Wuille
CC BY-SA 4.0
2021-10-03T01:59:22.360Z
I'm still trying to search on internet how to generate scriptpubkey , in the meanwhile i will read the bip you suggested ^^ txn , i will come back here when i finish
user6668201
CC BY-SA 4.0
2021-10-03T02:05:11.770Z
Here is one for P2PKH: https://bitcoin.stackexchange.com/a/65807/208
Pieter Wuille
CC BY-SA 4.0
2021-10-03T01:16:37.230Z
2021-10-03T01:16:37.230Z
Pieter Wuille
<p>One part of coinbase transaction is p2pkh ScriptPubKey (according to the book i read). Coinbase transaction here refers to the first transaction in a block , not Coinbase software/company.</p>
<p>Suppose i have all the data needed to build coinbase transaction (version,output,ect) except the p2pkh ScriptPubKey , and i have my address that i generate using bitcoin rpc <a href="https://developer.bitcoin.org/reference/rpc/getnewaddress.html" rel="nofollow noreferrer">getnewaddress</a> , how do i generate the p2pkh ScriptPubKey ?</p>
<p>Extra question : when i generate new address using bitcoin rpc getnewaddress , is the generated address a public key or private key ?</p>
<p>Sorry i'm new to bitcoin, i honestly don't know.</p>

<bitcoin-core><transactions><coinbase-transaction><p2pkh>
How to generate p2pkh ScriptPubKey for coinbase transaction
user6668201
# How to generate p2pkh ScriptPubKey for coinbase transaction

(Asked by: username_0 on 2021-10-03)

One part of coinbase transaction is p2pkh ScriptPubKey (according to the book i read). Coinbase transaction here refers to the first transaction in a block , not Coinbase software/company.

Suppose i have all the data needed to build coinbase transaction (version,output,ect) except the p2pkh ScriptPubKey , and i have my address that i generate using bitcoin rpc [getnewaddress](https://developer.bitcoin.org/reference/rpc/getnewaddress.html) , how do i generate the p2pkh ScriptPubKey ?

Extra question : when i generate new address using bitcoin rpc getnewaddress , is the generated address a public key or private key ?

Sorry i'm new to bitcoin, i honestly don't know.

**Tags:** bitcoin-core, transactions, coinbase-transaction, p2pkh


---

## 1 answers

### Answer by username_1 on 2021-10-03. Score: 1

> One part of coinbase transaction is p2pkh ScriptPubKey (according to the book i read).

That is (or at least, was) commonly the case, but there is no such requirement.

> Suppose i have all the data needed to build coinbase transaction (version,output,ect) except the p2pkh ScriptPubKey , and i have my address that i generate using bitcoin rpc getnewaddress , how do i generate the p2pkh ScriptPubKey ?

The coinbase transaction needs to have one or more outputs, which distribute the subsidy and fees gained to the miner(s). The miner can decide to pay out thenselves in whatever way they want. In that sense, the transaction outputs of the coinbase transaction are no different from those of any other output.

Now, most wallets want to be paid using one of the standard output types (P2PKH, P2SH, P2WPKH; there are a few more but that doesn't matter here). Each has a corresponding address type, so if you want the payout to such an address, you just need a way to compute the corresponding scriptPubKey. This is a very standard operation, implemented in pretty much any Bitcoin software library, and literally every wallet.

For P2PKH specifically, there are plenty of questions on how to do that on this site. For P2SH, refer to BIP13. For P2WPKH, see BIP141.

> Extra question : when i generate new address using bitcoin rpc getnewaddress , is the generated address a public key or private key ?

Modern wallets won't generate P2PKH addresses anymore; they are legacy. But the same applies for other address types.

In general, first the private key is generated (usually deterministically using BIP32). Then the corresponding public key is computed. Then that public key is hashed, and the hash is encoded as an address (for P2PKH or P2WPKH; for P2SH or P2WSH a script is involved as well).

> **Comments:**
> **username_0**: wow i'm amazed how bitcoin has changed so much that the book i read probably obsolete now . How did you know all of this ? is there any book / documentation you can recommend me to understand this and other aspect of bitcoin ?  
> **username_1**: It's not that the book sounds obsolete - it sounds more like it has always been misleading if it claims coinbase always have a P2PKH output. I'm not sure about books, but all big protocol/standard changes since ~2012 or so is described in BIPs. It sounds like you're trying to write mining software for some purpose; I suggest you look through the relevant BIPs (at least 13, 16, 141, 173, 350), and perhaps study other mining software implementations.  
> **username_1**: And I know because it is my job.  
> **username_0**: I'm still trying to search on internet how to generate scriptpubkey , in the meanwhile i will read the bip you suggested ^^ txn , i will come back here when i finish  
> **username_1**: Here is one for P2PKH: https://bitcoin.stackexchange.com/a/65807/208  

---

