<p>You need to do a few things to make the genesis block spendable, all in <code>validation.cpp</code> (untested):</p>

<ol>
<li><p>Allow tx connection, <a href="https://github.com/litecoin-project/litecoin/blob/0.14/src/validation.cpp#L2904" rel="nofollow noreferrer">L#2904</a>:</p>

<pre><code>if (*pindexPrev-&gt;phashBlock == chainparams.GetConsensus().hashGenesisBlock)
    // return true;
</code></pre></li>
<li><p>Skip coinbase amount check for genesis block, <a href="https://github.com/litecoin-project/litecoin/blob/0.14/src/validation.cpp#L1933" rel="nofollow noreferrer">L#1933</a>:</p>

<pre><code>if (block.vtx[0]-&gt;GetValueOut() &gt; blockReward &amp;&amp; block.GetHash() != chainparams.GetConsensus().hashGenesisBlock)
    return state.DoS(100,
                     error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]-&gt;GetValueOut(), blockReward),= REJECT_INVALID, "bad-cb-amount");
</code></pre></li>
<li><p>Skip writing undo data for genesis block <a href="https://github.com/litecoin-project/litecoin/blob/0.14/src/validation.cpp#L1947" rel="nofollow noreferrer">L#1947</a>:</p>

<pre><code>if (block.GetHash() != chainparams.GetConsensus().hashGenesisBlock)
{
    if (pindex-&gt;GetUndoPos().IsNull() || !pindex-&gt;IsValid(BLOCK_VALID_SCRIPTS))
        {
            if (pindex-&gt;GetUndoPos().IsNull()) {
                CDiskBlockPos _pos;
                if (!FindUndoPos(state, pindex-&gt;nFile, _pos, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40))
                    return error("ConnectBlock(): FindUndoPos failed");
                if (!UndoWriteToDisk(blockundo, _pos, pindex-&gt;pprev-&gt;GetBlockHash(), chainparams.MessageStart()))
                    return AbortNode(state, "Failed to write undo data");

                // update nUndoPos in block index
                pindex-&gt;nUndoPos = _pos.nPos;
                pindex-&gt;nStatus |= BLOCK_HAVE_UNDO;
            }

            pindex-&gt;RaiseValidity(BLOCK_VALID_SCRIPTS);
            setDirtyBlockIndex.insert(pindex);
    }
}
</code></pre></li>
</ol>

CC BY-SA 4.0
2018-10-04T15:14:43.933Z
Alright let me try with above change. after removing changes which I've given in **Update 2**
user1140237
CC BY-SA 4.0
2018-10-04T15:37:17.253Z
Updated [validation.cpp](https://gist.github.com/adneerav/207b36f12edd4f914e6365b43d5727d2) as per answer. but facing same issue. here I've [attached wallets screens](https://imgur.com/a/yTy9Qqa)
user1140237
CC BY-SA 4.0
2018-10-04T15:02:46.387Z
2018-10-04T15:02:46.387Z
JBaczuk
<p><strong><em>Please check the whole question once before giving negative marking or Mark as duplicate of</em></strong> </p>

<p><a href="https://bitcoin.stackexchange.com/questions/10009/why-can-t-the-genesis-block-coinbase-be-spent">Why can’t the genesis block coinbase be spent?</a></p>

<p><a href="https://bitcoin.stackexchange.com/questions/20181/why-i-cannot-get-transaction-from-genesis-block">Why I cannot get transaction from genesis block [duplicate]</a></p>

<p>I am creating AltCoin from <a href="https://github.com/litecoin-project/litecoin" rel="nofollow noreferrer">litecoin</a> source.And using <a href="https://github.com/lhartikk/GenesisH0" rel="nofollow noreferrer">GenesisHO</a> generating genesis block details like nonce ,genesis hash , merkle etc.</p>

<p>While generating genesis block I have changed the coin value parameters in genesis coin value. that is <code>-v</code> parameters and generated genesis hash and merkle etc.</p>

<p>I've done changes regarding genesis , nonce, coins for genesis block.</p>

<pre><code>genesis = CreateGenesisBlock(1538404994, 2086003386, 0x1e0ffff0, 1, 50000 * COIN);
</code></pre>

<p>eg. I want to premine 50,000 coins in genesis block. <strong><em>I don't want</em></strong> give condition in validation.cpp like if block height 1 than reward should be 50,000.</p>

<p><strong><em>I've generated pub key and used the same pub key while generating genesis hash.So I can use that genesis block coins by importing private key of that pub key.</em></strong></p>

<p>After all above change in source,I've build daemon ,cli ,tx and qt from same source.</p>

<p><strong><em>Next</em></strong> </p>

<p>From cli I have executed command(<code>coin-cli generate 1</code>) to generate one block so I can get genesis block coin(Yes!! initially it will be in immature state after x(which I've set to 1) amount of block it will be in mature state). And imported that private key in wallet.</p>

<p><strong><em>Result of above :</em></strong></p>

<p>After execution of <strong><code>coin-cli generate 1</code></strong> genesis coins are generated.Displayed in wallet and account under account name <strong><em>""</em></strong></p>

<p>Started Mining (using cpuminer) which has another account's address. <strong><em>And after few blocks genesis block coins converted to mature state</em></strong></p>

<blockquote>
  <p><strong><em>Problem/Issue</em></strong></p>
  
  <p><strong><em>Now when i tried to transfer from that genesis block coins its not transferring to any address.Its not displaying in qt wallet but using
  cli command its displaying balance.</em></strong></p>
</blockquote>

<p>So where do I need to make other changes to make that genesis coin spendable.</p>

<blockquote>
  <p><strong>Transactions details</strong></p>
</blockquote>

<p><a href="https://i.sstatic.net/Yk67i.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Yk67i.png" alt="enter image description here"></a></p>

<blockquote>
  <p><strong>Balance details from qt wallet and command</strong></p>
</blockquote>

<p><a href="https://i.sstatic.net/cacZ6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cacZ6.png" alt="enter image description here"></a>
For mining using cpuminer</p>

<p>Litecoin source : <a href="https://github.com/litecoin-project/litecoin/tree/0.14" rel="nofollow noreferrer">https://github.com/litecoin-project/litecoin/tree/0.14</a></p>

<blockquote>
  <p><strong>UPDATE</strong></p>
</blockquote>

<p>I've tried &amp; follow steps from <a href="https://bitcoin.stackexchange.com/a/79064/54360">this answer too</a>
After updating as per from above answer in <a href="https://gist.github.com/adneerav/1d16d5957ae56b8dc240a0dc79317b9e" rel="nofollow noreferrer">validation.cpp here is the link of same</a></p>

<blockquote>
  <p><strong>Update 2</strong></p>
</blockquote>

<p>Changes mentioned <a href="https://bitcoin.stackexchange.com/a/79064/54360">in answer</a> regarding validation.cpp &amp; updated <a href="https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b" rel="nofollow noreferrer">validation.cpp file here</a> &amp; same updated change mentioned below line wise</p>

<p><a href="https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b#file-validation-cpp-L1772" rel="nofollow noreferrer"> Changes in special case for the genesis block, skipping connection of its transactions (its coinbase is unspendable)</a></p>

<p><a href="https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b#file-validation-cpp-L1830" rel="nofollow noreferrer">Changes for assert(pindex->pprev);</a></p>

<p><a href="https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b#file-validation-cpp-L1677" rel="nofollow noreferrer">Added WriteUndoDataForBlock method :</a></p>

<p><a href="https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b#file-validation-cpp-L1966" rel="nofollow noreferrer">Change to skip writing undo data for genesis block</a></p>

<p><strong><em>After updating above things it give error <code>Segmentation fault (core dumped)</code></em></strong></p>

<p><a href="https://gist.github.com/adneerav/e537ee587500b6861c062c99d35f8a9f" rel="nofollow noreferrer">And here is debug.log details</a></p>

<p>Thanks.</p>

CC BY-SA 4.0
2018-10-03T17:33:44.260Z
Did you make any adjustments to `validation.cpp`, specifically this line? https://github.com/litecoin-project/litecoin/blob/0.14/src/validation.cpp#L1753
JBaczuk
CC BY-SA 4.0
2018-10-04T08:27:34.190Z
@JBaczuk Well actually as a newbie.What i tried is commented return true; statement and build again but it give error when I started daemon Segmentation fault (core dumped). Do i need to make any change in that file for that ?
user1140237
CC BY-SA 4.0
2018-10-04T09:43:16.053Z
@JBaczuk please check question.I've added update
user1140237
CC BY-SA 4.0
2018-10-04T11:57:42.430Z
You're right to comment that line. It segfaults b/c its trying to reference a previous block when it is on the Genesis, but there isn't one. Look for `assert(pindex->pprev)`. All the changes you need to make are in that file.
JBaczuk
CC BY-SA 4.0
2018-10-04T14:51:42.190Z
@JBaczuk Ohh okay but once please check my updated question mentioned as **Update 2**
user1140237
<altcoin><litecoin><altcoin-development><genesis-block><litecoin-qt>
Premine coins from genesis block are gone after one transaction from account/wallet
user1140237
# Premine coins from genesis block are gone after one transaction from account/wallet

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

***Please check the whole question once before giving negative marking or Mark as duplicate of***

[Why can’t the genesis block coinbase be spent?](https://bitcoin.stackexchange.com/questions/10009/why-can-t-the-genesis-block-coinbase-be-spent)

[Why I cannot get transaction from genesis block [duplicate]](https://bitcoin.stackexchange.com/questions/20181/why-i-cannot-get-transaction-from-genesis-block)

I am creating AltCoin from [litecoin](https://github.com/litecoin-project/litecoin) source.And using [GenesisHO](https://github.com/lhartikk/GenesisH0) generating genesis block details like nonce ,genesis hash , merkle etc.

While generating genesis block I have changed the coin value parameters in genesis coin value. that is `-v` parameters and generated genesis hash and merkle etc.

I've done changes regarding genesis , nonce, coins for genesis block.

```
genesis = CreateGenesisBlock(1538404994, 2086003386, 0x1e0ffff0, 1, 50000 * COIN);

```

eg. I want to premine 50,000 coins in genesis block. ***I don't want*** give condition in validation.cpp like if block height 1 than reward should be 50,000.

***I've generated pub key and used the same pub key while generating genesis hash.So I can use that genesis block coins by importing private key of that pub key.***

After all above change in source,I've build daemon ,cli ,tx and qt from same source.

***Next***

From cli I have executed command(`coin-cli generate 1`) to generate one block so I can get genesis block coin(Yes!! initially it will be in immature state after x(which I've set to 1) amount of block it will be in mature state). And imported that private key in wallet.

***Result of above :***

After execution of **`coin-cli generate 1`** genesis coins are generated.Displayed in wallet and account under account name ***""***

Started Mining (using cpuminer) which has another account's address. ***And after few blocks genesis block coins converted to mature state***

> ***Problem/Issue***
>
> ***Now when i tried to transfer from that genesis block coins its not transferring to any address.Its not displaying in qt wallet but using
> cli command its displaying balance.***

So where do I need to make other changes to make that genesis coin spendable.

> **Transactions details**

[![enter image description here](https://i.sstatic.net/Yk67i.png)](https://i.sstatic.net/Yk67i.png)

> **Balance details from qt wallet and command**

[![enter image description here](https://i.sstatic.net/cacZ6.png)](https://i.sstatic.net/cacZ6.png)
For mining using cpuminer

Litecoin source : <https://github.com/litecoin-project/litecoin/tree/0.14>

> **UPDATE**

I've tried & follow steps from [this answer too](https://bitcoin.stackexchange.com/a/79064/54360)
After updating as per from above answer in [validation.cpp here is the link of same](https://gist.github.com/adneerav/1d16d5957ae56b8dc240a0dc79317b9e)

> **Update 2**

Changes mentioned [in answer](https://bitcoin.stackexchange.com/a/79064/54360) regarding validation.cpp & updated [validation.cpp file here](https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b) & same updated change mentioned below line wise

[Changes in special case for the genesis block, skipping connection of its transactions (its coinbase is unspendable)](https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b#file-validation-cpp-L1772)

[Changes for assert(pindex->pprev);](https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b#file-validation-cpp-L1830)

[Added WriteUndoDataForBlock method :](https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b#file-validation-cpp-L1677)

[Change to skip writing undo data for genesis block](https://gist.github.com/adneerav/d591267c422850cbff842652341afd8b#file-validation-cpp-L1966)

***After updating above things it give error `Segmentation fault (core dumped)`***

[And here is debug.log details](https://gist.github.com/adneerav/e537ee587500b6861c062c99d35f8a9f)

Thanks.

**Tags:** altcoin, litecoin, altcoin-development, genesis-block, litecoin-qt

> **Comments:**
> **username_1**: Did you make any adjustments to `validation.cpp`, specifically this line? https://github.com/litecoin-project/litecoin/blob/0.14/src/validation.cpp#L1753  
> **username_0**: @username_1 Well actually as a newbie.What i tried is commented return true; statement and build again but it give error when I started daemon Segmentation fault (core dumped). Do i need to make any change in that file for that ?  
> **username_0**: @username_1 please check question.I've added update  
> **username_1**: You're right to comment that line. It segfaults b/c its trying to reference a previous block when it is on the Genesis, but there isn't one. Look for `assert(pindex->pprev)`. All the changes you need to make are in that file.  
> **username_0**: @username_1 Ohh okay but once please check my updated question mentioned as **Update 2**  

---

## 1 answers

### Answer by username_1 on 2018-10-04. Score: 1

You need to do a few things to make the genesis block spendable, all in `validation.cpp` (untested):

1. Allow tx connection, [L#2904](https://github.com/litecoin-project/litecoin/blob/0.14/src/validation.cpp#L2904):

   ```
   if (*pindexPrev->phashBlock == chainparams.GetConsensus().hashGenesisBlock)
       // return true;

   ```
2. Skip coinbase amount check for genesis block, [L#1933](https://github.com/litecoin-project/litecoin/blob/0.14/src/validation.cpp#L1933):

   ```
   if (block.vtx[0]->GetValueOut() > blockReward && block.GetHash() != chainparams.GetConsensus().hashGenesisBlock)
       return state.DoS(100,
                        error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]->GetValueOut(), blockReward),= REJECT_INVALID, "bad-cb-amount");

   ```
3. Skip writing undo data for genesis block [L#1947](https://github.com/litecoin-project/litecoin/blob/0.14/src/validation.cpp#L1947):

   ```
   if (block.GetHash() != chainparams.GetConsensus().hashGenesisBlock)
   {
       if (pindex->GetUndoPos().IsNull() || !pindex->IsValid(BLOCK_VALID_SCRIPTS))
           {
               if (pindex->GetUndoPos().IsNull()) {
                   CDiskBlockPos _pos;
                   if (!FindUndoPos(state, pindex->nFile, _pos, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40))
                       return error("ConnectBlock(): FindUndoPos failed");
                   if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart()))
                       return AbortNode(state, "Failed to write undo data");

                   // update nUndoPos in block index
                   pindex->nUndoPos = _pos.nPos;
                   pindex->nStatus |= BLOCK_HAVE_UNDO;
               }

               pindex->RaiseValidity(BLOCK_VALID_SCRIPTS);
               setDirtyBlockIndex.insert(pindex);
       }
   }

   ```

> **Comments:**
> **username_0**: Alright let me try with above change. after removing changes which I've given in **Update 2**  
> **username_0**: Updated [validation.cpp](https://gist.github.com/adneerav/207b36f12edd4f914e6365b43d5727d2) as per answer. but facing same issue. here I've [attached wallets screens](https://imgur.com/a/yTy9Qqa)  

---

