user131787: I have tried to serialize as follows without success: bitcoin tag v22.0 from github.
In the file src/miner.cpp and the function
function std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
I have placed the line std::cout << pblock << std::endl; at the very end before it returns (Here). The value that is printed to the terminal is:
0x7fc9f4009410
This is too little data, I would expect the entire block data to be serialized and printed in hex. What am I doing wrong? I know pblock is a pointer to a CBlock class, but it should still work.
What is the proper way to serialize CBlock data, and also the CBlockHeader data?
Thank you!

user112226: Since pblock is a pointer, you are printing an address. Dereference it to get the format you want:
std::cout << *pblock << std::endl;


131787: <p>I have tried to serialize as follows without success: bitcoin tag v22.0 from github.</p>
<p>In the file <code>src/miner.cpp</code> and the function</p>
<p><a href="https://github.com/bitcoin/bitcoin/blob/v22.0/src/miner.cpp#L102" rel="nofollow noreferrer"><code>function std::unique_ptr&lt;CBlockTemplate&gt; BlockAssembler::CreateNewBlock(const CScript&amp; scriptPubKeyIn)</code></a></p>
<p>I have placed the line <code>std::cout &lt;&lt; pblock &lt;&lt; std::endl;</code> at the very end before it returns (<a href="https://github.com/bitcoin/bitcoin/blob/v22.0/src/miner.cpp#L185" rel="nofollow noreferrer">Here</a>). The value that is printed to the terminal is:</p>
<p><code>0x7fc9f4009410</code></p>
<p>This is too little data, I would expect the entire block data to be serialized and printed in hex. What am I doing wrong? I know pblock is a pointer to a CBlock class, but it should still work.</p>
<p>What is the proper way to serialize CBlock data, and also the CBlockHeader data?</p>
<p>Thank you!</p>
 112226: <p>Since <code>pblock</code> is a pointer, you are printing an address. Dereference it to get the <a href="https://github.com/bitcoin/bitcoin/blob/a0988140b71485ad12c3c3a4a9573f7c21b1eff8/src/primitives/block.cpp#L16" rel="nofollow noreferrer">format</a> you want:</p>
<pre><code>std::cout &lt;&lt; *pblock &lt;&lt; std::endl;
</code></pre>
