Author

Topic: *** Complete Guide on How to Create a New Alt Coin – Update 2019 *** (Read 2155 times)

newbie
Activity: 2
Merit: 0
Hello everyone.

I am moving my older alt-coin from bitcoin core 9.0 to bitcoin core 13.0.

I have everything I can think of done, but I seem to be missing one thing.

If anyone can help, it would be greatly appreciated!

Here is the error that I am getting.

Run the wallet, get the following :
bitcoin-qt: main.cpp:1856: void InvalidChainFound(CBlockIndex*): Assertion `tip' failed.
Aborted (core dumped)

Debug log shows this :

2023-01-04 21:00:11 ERROR: ConnectBlock: Consensus::CheckBlock: high-hash, proof of work failed (code
16)
2023-01-04 21:00:11 InvalidChainFound: invalid block=000005232c6fe11ca78e898bcd61a031b461dee02ef950dae
74423c3fcbd8e69  height=0  log2_work=20.000001  date=2018-05-31 20:33:34

Now, this IS the genesis block that was created on the 9.0 version.


Any help would be greatly appreciated!

newbie
Activity: 2
Merit: 0
Lets do it together. i just starting to new own bitcoin on v22.

Has anyone given this a shot with the latest Bitcoin repo? (22.x) I'm going to dive in shortly and report back.....
newbie
Activity: 1
Merit: 0
Has anyone given this a shot with the latest Bitcoin repo? (22.x) I'm going to dive in shortly and report back.....
newbie
Activity: 22
Merit: 0
hi guys,
I'm having a weird issue, sometimes it would confirm transactions and sometimes it wouldn't, I don't understand the issue here, I saw the guide I followed that but I got other issues however I switched back to my original source code. I'm using Litecoin latest code

check this screenshot and check the timestamp, many blocks were mined and the number is incrementing and those are still in mempool



Image link https://ibb.co/nkBpZzM

newbie
Activity: 29
Merit: 6
@Toki.Fujinami which software are you using in order to mine?
newbie
Activity: 25
Merit: 1
How are you mining? via generatetoaddress or a miner?

hi can you help me? Same issue
newbie
Activity: 25
Merit: 1
Hello
i hope you can help me
i cloned a coin bitcoinpos,all is ok,block genesis generated but i can't mine pow blocks,i tried with generatetoaddress also setting a pool,nothing,what i do?
--------------------------------------------------
class CMainParams : public CChainParams {
public:
    CMainParams() {
        strNetworkID = CBaseChainParams::MAIN;
        consensus.signet_blocks = false;
        consensus.signet_challenge.clear();
        consensus.nSubsidyHalvingInterval = 2200000;
        consensus.BIP16Exception = uint256S("0x00000bcd2d9ccbb28606a8b2d962b97394f612bf6e021ce1d64d71cecb008029");
        consensus.BIP34Height = 1;
        consensus.BIP34Hash = uint256S("0x00000b3b403a2b37780a8dc3813e02463cbaceab135efffe4aaacf0446f862d5");
        consensus.BIP65Height = 1;
        consensus.BIP66Height = 1;
        consensus.CSVHeight = 1;
        consensus.SegwitHeight = 1;
        consensus.MinBIP9WarningHeight = consensus.SegwitHeight + consensus.nMinerConfirmationWindow;
        consensus.BPSRewardMatchStep = 6000;
        consensus.BPSRewardMatchHeight = 3 * consensus.BPSRewardMatchStep;
        consensus.BPSDiffAdjHeight = 13000;
        consensus.BPSColdStakeEnableHeight = 26000;
        consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
        consensus.posLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
        consensus.nPowTargetTimespan = 10 * 1 * 60; // every 10 blocks
        consensus.nPowTargetSpacing = 1 * 60;
        consensus.fPowAllowMinDifficultyBlocks = false;
        consensus.fPowNoRetargeting = false;
        consensus.fPoSNoRetargeting = false;
        consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
        consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
        consensus.nLastPOWBlock = 5000;
        consensus.nMPoSRewardRecipients = 10;
        consensus.nFirstMPoSBlock = consensus.nLastPOWBlock +
                                    consensus.nMPoSRewardRecipients +
                                    COINBASE_MATURITY;
        consensus.nLastMPoSBlock = consensus.BPSColdStakeEnableHeight;
        consensus.nEnableHeaderSignatureHeight = 0;
        consensus.nCheckpointSpan = COINBASE_MATURITY;
        consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
        consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
        consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008

        // Deployment of Taproot (BIPs 340-342)
        consensus.vDeployments[Consensus::DEPLOYMENT_TAPROOT].bit = 2;
        consensus.vDeployments[Consensus::DEPLOYMENT_TAPROOT].nStartTime = 1199145601; // January 1, 2008
        consensus.vDeployments[Consensus::DEPLOYMENT_TAPROOT].nTimeout = 1230767999; // December 31, 2008

        consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000000000000001"); //block 1
        consensus.defaultAssumeValid = uint256S("0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); //block 1
newbie
Activity: 10
Merit: 0
Hi

Was wondering if anyone has come across this error before when running the getblocktemplate method

error -10: bitcoin is downloading blocks...

I cant seem to get past this error. Has anyone ever experienced anything similar? Any suggestions welcomed.

Thanks

newbie
Activity: 7
Merit: 0
Hey,

I wanna help you guys by solving a problem,
If your confirmations are going to fast (sometimes x100 faster than blocks mined) than you have to lower the coin maturity, i still didn't find out why this is happening and i will soon test other coin maturity amounts, but i know 100 is not working proberly and 10 does.

after months of searching and trying things out i managed to get a good working coin on version 0.18.1 (windows included).
(thx TheWolf666 for helping me with the segwit and IsNullDummyEnabled problem that fixed the transactions that stay forever in memory pool Smiley
(For the people that come here for the same problem under here you can see a copy of a piece out of the tutorial to fix this problem

Validation.cpp is not finished yet. We have a problem with SEGWIT. It cannot work at height 1. So in the beginning, we need to disable some checks, that will have to be re-enabled when the blockchain has at least 2000 blocks mined. You have to experiment here; the goal of this tutorial is not to deal with the blockchain maintenance.

bool IsWitnessEnabled needs to return true in all cases. So just add return true; at the beginning of the function.

IsNullDummyEnabled has the same problem, do the same to that function.

Find this “return state.DoS(100, false, REJECT_INVALID, "bad-cb-height", false, "block height mismatch in coinbase");” and comment it.

End of the validation.cpp customization.

h)   Other code modifications.
There are more modifications, spread everywhere that needs to be fixed in order to get the coin to work correctly.

validation.h  :
-   you need to change the DEFAULT_MAX_TIP_AGE to something very large (60*60*24*365 for example). This is temporary. This is the interval when the blockchain is not mining. At starting you might have a genesis made long time ago, and not have mined for a while, so that this has to be changed or your Coin will not work.
-   DEFAULT_CHECKPOINTS_ENABLED = true; needs to be changed to false, or your coin will try to verify that you are on the Bitcoin blockchain, which you are not.

\rpc\mining.cpp :
Another SEGWIT test that needs to be removed:

Code:
throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the segwit rule set (call with {\"rules\": [\"segwit\"]})");
Comment this line.

net_processing.cpp :
-   STALE_CHECK_INTERVAL need to be changed to a large value to avoid having a STALE error, this is again temporary, once the blockchain is mined by many people, it can be back to the original values. (3600*24*365 for example)
-   STALE_RELAY_AGE_LIMIT same for this static variable.

\qt\bitcoingui.cpp
Get rid of the loading form set this variable to 0.

Code:
qint64 secs = blockDate.secsTo(currentDate);
becomes qint64 secs=0;

Now you should have a functional Coin. But you need to mine.

Greetings,
Jonas Bellaert
newbie
Activity: 1
Merit: 0
Use this to mine the genesis block

Code:
static void MineGenesis(CBlockHeader &genesisBlock, const uint256 &powLimit, bool noProduction) {
    if (noProduction) genesisBlock.nTime = std::time(nullptr);
    genesisBlock.nNonce = std::time(nullptr);

    printf("NOTE: Genesis nTime = %u \n", genesisBlock.nTime);
    printf("WARN: Genesis nNonce (BLANK!) = %u \n", genesisBlock.nNonce);

    arith_uint256 besthash;
    memset(&besthash, 0xFF, 32);
    arith_uint256 hashTarget = UintToArith256(powLimit);
    printf("Target: %s\n", hashTarget.GetHex().c_str());
    arith_uint256 newhash = UintToArith256(genesisBlock.GetHash());
    while (newhash > hashTarget) {
        genesisBlock.nNonce++;
        if (genesisBlock.nNonce == 0) {
            printf("NONCE WRAPPED, incrementing time\n");
            ++genesisBlock.nTime;
        }
        // If nothing found after trying for a while, print status
        if ((genesisBlock.nNonce & 0xffff) == 0)
            printf("nonce %08X: hash = %s target=%s \r",
                   genesisBlock.nNonce, newhash.ToString().c_str(),
                   hashTarget.ToString().c_str());

        if (newhash < besthash) {
            besthash = newhash;
            printf("New best: %s\n", newhash.GetHex().c_str());
        }
        newhash = UintToArith256(genesisBlock.GetHash());
    }
    printf("\nGenesis nTime = %u \n", genesisBlock.nTime);
    printf("Genesis nNonce = %u \n", genesisBlock.nNonce);
    printf("Genesis nBits: %08x\n", genesisBlock.nBits);
    printf("Genesis Hash = %s\n", newhash.ToString().c_str());
    printf("Genesis Hash Merkle Root = %s\n", genesisBlock.hashMerkleRoot.ToString().c_str());
    printf("Genesis Hash Merkle Root = %s\n", genesisBlock.hashMerkleRoot.ToString().c_str());
}

call like this

Code:
        genesis = CreateGenesisBlock(std::time(nullptr), 546521654, 0x1d00ffff, 1, 50 * COIN);
        MineGenesis(genesis, consensus.powLimit, true);

Then change the asserts with the merkel and hash generated by this algo. It will work on the latest version of Bitcoin core.

Thanks for the tutorial, that's very helpful. I tried the MineGenesis() function (on windows 10) based on the latest bitcoin core. It's been running for more than 2+ hours but couldn't find the genesis block yet, I wonder if that is normal and roughly how long it'd take to mine the genesis block?
newbie
Activity: 1
Merit: 0
Thank you for your tutorial! I made a altcoin for fun, But i meet a problem which is (can't broadcast immediately no witness yet) im forked bitcoin core 0.16.0. If u can help me solve the problem i love to donate some ETH for your help. Grin Grin
newbie
Activity: 12
Merit: 8
Hi pal,

Followed this tutorial and now have two working instances of my Alt running. I decided to try and mine via RPC (still available on v0.18) with a simple python script I found on github (ntgbtminer). Problem is I'm getting the error

    Consensus::CheckBlock: bad-txns-vout-toolarge

Sorry for the off topic question but I could do with a second opinion.

Cheers
newbie
Activity: 12
Merit: 0
Code:
chainparams.cpp:27:5: error: ‘arith_uint256’ was not declared in this scope
errors for more than just line 27. What I'm doing to put your code into chainparams.cpp, is copy and pasting https://raw.githubusercontent.com/NicolasChoukroun/altcoin-genesis/master/creategenesis.cpp under all of the #include in chainparams.cpp. There is probably something I'm doing wrong here, and I'm way too new to C++ to know what I'm doing wrong. Any help would be greatly appreciated!

You need to add this before the mining function
Code:
#include
newbie
Activity: 4
Merit: 0
@isp92074 don't activate SegWit at the beginning.
how to do it ?,
I changed some files https://github.com/isp92074/b3c, but still only regtest version miners works ok
isp@isp:~/ntgbtminer$ python3 ntgbtminer.py Test 2N3SryuVcYR3y8wgMcw98T2ek3VU8HpoSeg
Mining block template, height 7...
    0.0000 KH/s

Solved a block! Block hash: 1abbc23f5a921cfe88d1a4bbcd1411340c0e25353469a35da47816ab69d27ef0
Submitting: 00000020120e25591b008f7b2c1fce3affb687a261a6ee6d3094efd0e34d8e185c21b15fa5be88a 1a5723be3c71c3213a0128d38668bc9c631a9a3f62c7ebc092001682979228f60ffff7f20000000 000101000000010000000000000000000000000000000000000000000000000000000000000000f fffffff0a01075465737400000000ffffffff0100f2052a010000001976a9146fe4b6ca0ddb5ed5 9215dabb005292207550b5a788ac00000000

Mining block template, height 8...
    160.6757 KH/s

-----------------------------------------

on mainnet some errors
python3 ntgbtminer.py Test bc1qaaak4zwyq2dqleztjmz8hy407mlx08nl7wjneu
Traceback (most recent call last):
  File "ntgbtminer.py", line 482, in
    standalone_miner(sys.argv[1].encode().hex(), sys.argv[2])
  File "ntgbtminer.py", line 460, in standalone_miner
    block_template = rpc_getblocktemplate()
  File "ntgbtminer.py", line 69, in rpc_getblocktemplate
    return rpc("getblocktemplate", [{"rules": ["segwit"]}])
  File "ntgbtminer.py", line 52, in rpc
    with urllib.request.urlopen(request) as f:
  File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

in bitcoinqt console


getblocktemplate

Bitcoin Core Clone is in initial sync and waiting for blocks... (code -10)

generatetoaddress 1 bc1qaaak4zwyq2dqleztjmz8hy407mlx08nl7wjneu

CreateNewBlock: TestBlockValidity failed: unexpected-witness, ContextualCheckBlock : unexpected witness data found (code -1)

newbie
Activity: 29
Merit: 6
@isp92074 don't activate SegWit at the beginning.
newbie
Activity: 4
Merit: 0
How are you mining? via generatetoaddress or a miner?
1)generatetoaddress error
CreateNewBlock :TestBlockValidity failed unexpected-witness ContextualCheckBlock unexpected witness data found code -1
newbie
Activity: 7
Merit: 0
Take a look at this coin just launched.

https://github.com/kanchiworld/kanchan

It is fairly new, and they are giving away free coins to early adopters. It may be a good idea to get in early.


What is this coin? Is there a purpose to it? Any details of mining etc?
newbie
Activity: 4
Merit: 0
Hello, I am having some problems with the genesis block. I am new to C++, but what I know is that because my assert of the genesis hash is failing, it means that I am putting the wrong genesis hash. Here is my code for generating the genesis hash (I'm using the genesis generator from https://github.com/hashcrack256/node-genesis-block):
Code:
node genesis -p 040839e4f568674e93581cf1db43a7b09a8ba9d440bad64b296c1554cf7c9c9714d1b5d19c3aadc01647ab41266d4fe2745afa72166c3d69a66cd35c4f3a0b5de0 -t 1618258400 -n 404483 -a sha256d -v 5000000000 -z "Ion got it on me." -b 0x1d00ffff
And in my chainparams.cpp:
Code:
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
    const char* pszTimestamp = "Ion got it on me.";
    const CScript genesisOutputScript = CScript() << ParseHex("040839e4f568674e93581cf1db43a7b09a8ba9d440bad64b296c1554cf7c9c9714d1b5d19c3aadc01647ab41266d4fe2745afa72166c3d69a66cd35c4f3a0b5de0") << OP_CHECKSIG;
    return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
}
As well as:
Code:
        genesis = CreateGenesisBlock(1618258400, 404483, 0x1d00ffff, 1, 50 * COIN);
        consensus.hashGenesisBlock = genesis.GetHash();
        assert(consensus.hashGenesisBlock == uint256S("0x000005a48ef8e68ac2f26d0987784eaace9dc304f9f579a652f83c958d5fadb1"));
        assert(genesis.hashMerkleRoot == uint256S("0x941d67c6b23e01ae4f16284613133be33c46d23d38fe150c34ab92bc7bd04176"));
What exactly am I missing? What missing parameter am I missing that affects the genesis hash, so that the assert fails? The reason I'm not using your provided genesis generator is because it gives me a ton of
Code:
chainparams.cpp:27:5: error: ‘arith_uint256’ was not declared in this scope
errors for more than just line 27. What I'm doing to put your code into chainparams.cpp, is copy and pasting https://raw.githubusercontent.com/NicolasChoukroun/altcoin-genesis/master/creategenesis.cpp under all of the #include in chainparams.cpp. There is probably something I'm doing wrong here, and I'm way too new to C++ to know what I'm doing wrong. Any help would be greatly appreciated!
newbie
Activity: 29
Merit: 6
How are you mining? via generatetoaddress or a miner?
newbie
Activity: 4
Merit: 0
@isp92074 I had the same error, please check that SegWit height is not 1.
At the beginning try to leave the SegWit height as is.
Height was 0))now I made a consensus.segwit height  as in last bitcoin, but the error persists. testnet works without this error
newbie
Activity: 29
Merit: 6
@isp92074 I had the same error, please check that SegWit height is not 1.
At the beginning try to leave the SegWit height as is.
newbie
Activity: 4
Merit: 0
Thanks your guide helps cloning Bitcoin latest version.

hi sir ,
dear may be you help me .
i do all by your instruction but have some errors

Validation.cpp is not finished yet. We have a problem with SEGWIT. It cannot work at height 1. So in the beginning, we need to disable some

1)IsNullDummyEnabled has the same problem, do the same to that function return true/


===========
Suggested: IsNullDummyEnabled has the same problem, do the same to that function.
Question: Cant find it?!! Is it in validation.cpp on the latest bitcoin version?

=> this I do not understand.

===========



2)If ccminer cannot mine, then you can use my fixed version here: https://github.com/NicolasChoukroun/stratum



In the latest version I do not find a function IsNullDummyEnabled
1) to replace the return
2) I do not find C ++ stratum files for change
3) After compiling the QT wallet, the nodes are well connected and the sync is finished the tick in the lower right corner, but
in console command result  

getblocktemplate
= Bitcoin core is in initial sync and waiting for blocks code -10

but still still problems solo mining in yiimp pool issues the same synchronization error for added coin..

Stratum server issues a message - unknown method getblocktemplate 192.168.0.104
-
started easymainer on 192.168.0.4  issues a message
2 miner theads started using sha25 algo
HTTP request failed
json_rpc_call failed  

Please advise how to how to solve these problems??
 i need solo mininig on cpu for my cloned version & remove the synchronization error in the new Bitcoin core 21.99
copper member
Activity: 1190
Merit: 3
Truly speaking, the information provided by you is too technical for me but I see how step by step it is presented and made it simple. At least the first time I came to know about specific points on the creation of new altcoin. Would like to appreciate your efforts in putting this information altogether.
newbie
Activity: 1
Merit: 0
Take a look at this coin just launched.

https://github.com/kanchiworld/kanchan

It is fairly new, and they are giving away free coins to early adopters. It may be a good idea to get in early.
newbie
Activity: 7
Merit: 0
You're correct.
Setgenerate has been removed a while ago. I'm late to the party.

I will need to figure out a way to mine these before spending big $$.

Thank you for responding so quickly.

You cannot mine like this. You need to use a stratum pool.
Solo mining has been disabled for a long time (unless they added it back? but I am doubtful)

You need to setup a mining pool, and it is quite a complicated process.
A good start is here: https://github.com/tpruvot/yiimp
Take a cheap dedicated server here for example: https://www.hetzner.com/sb
Use an install script like this: https://github.com/xavatar/yiimp_install_scrypt

Do not let anyone install it for you, services will generally have some sort of spyware, and will mine partially for them, so it is not worth.
newbie
Activity: 7
Merit: 0
Interesting..I thought if the blockchain is brand new and difficulty is very low, you should be able to mine it locally before setting up servers and pools etc.
Thanks for the info though.

You cannot mine like this. You need to use a stratum pool.
Solo mining has been disabled for a long time (unless they added it back? but I am doubtful)

You need to setup a mining pool, and it is quite a complicated process.
A good start is here: https://github.com/tpruvot/yiimp
Take a cheap dedicated server here for example: https://www.hetzner.com/sb
Use an install script like this: https://github.com/xavatar/yiimp_install_scrypt

Do not let anyone install it for you, services will generally have some sort of spyware, and will mine partially for them, so it is not worth.
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
You cannot mine like this. You need to use a stratum pool.
Solo mining has been disabled for a long time (unless they added it back? but I am doubtful)

You need to setup a mining pool, and it is quite a complicated process.
A good start is here: https://github.com/tpruvot/yiimp
Take a cheap dedicated server here for example: https://www.hetzner.com/sb
Use an install script like this: https://github.com/xavatar/yiimp_install_scrypt

Do not let anyone install it for you, services will generally have some sort of spyware, and will mine partially for them, so it is not worth.
newbie
Activity: 7
Merit: 0
Thank you.
I've reset all heights to 0 (previously I had them at 1) and returning true from the "if" condition below.

I was able to start the xxxcoind.exe and it used the default %APPDATA% folder.

When I tried to start the wallet ( xxx-qt.exe or xxx-cli.exe), it complained about unable to lock the data directory.

Is this by design, that you cannot start daemon and wallet on the same node?
I ended up changing the data directory for wallet to somewhere else like "C:\data". I'm guessing this will duplicate the entire chain?

Then stopped the wallet and running this command in a loop to mine few blocks. Not sure how long this will take on a CPU or where I can check if the transactions are being processed (since I cannot open qt-exe while CLI.exe has locked the wallet)

Code:
cli-exe -generate 1



@TheWolf666

Thank you for the great guide. I've followed the instructions to make changes and able to build the code on Windows. But I'm unable to start the wallet or the coin daemon server.
It fails in this code, in tx_check.cpp.

Code:
if (tx.IsCoinBase())
    {
        if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 100)
            return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cb-length");
    }

I see that in Chainparams.cpp, there are new variables being set in the latest core code, for example
Code:
consensus.SegwitHeight = 481824;
I've set this to 1 but still no use.

Any pointers? I would like to create a brand new blockchain from start using bitcoin core code for experimental purposes.

Thanks in advance

I would comment the
Code:
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cb-length");
and do consensus.SegwitHeight = 0;

You are starting a new blockchain so you need all the BIPs starting at zero.
If you have a validation error, temporary comment the error, so that the first block (genesis) can be written into the blockchain.
The first block is always a problem, because the authors of Bitcoin Core are not helping the altcoin developers with their validation tests that are specific to Bitcoin.

full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
@TheWolf666

Thank you for the great guide. I've followed the instructions to make changes and able to build the code on Windows. But I'm unable to start the wallet or the coin daemon server.
It fails in this code, in tx_check.cpp.

Code:
if (tx.IsCoinBase())
    {
        if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 100)
            return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cb-length");
    }

I see that in Chainparams.cpp, there are new variables being set in the latest core code, for example
Code:
consensus.SegwitHeight = 481824;
I've set this to 1 but still no use.

Any pointers? I would like to create a brand new blockchain from start using bitcoin core code for experimental purposes.

Thanks in advance

I would comment the
Code:
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cb-length");
and do consensus.SegwitHeight = 0;

You are starting a new blockchain so you need all the BIPs starting at zero.
If you have a validation error, temporary comment the error, so that the first block (genesis) can be written into the blockchain.
The first block is always a problem, because the authors of Bitcoin Core are not helping the altcoin developers with their validation tests that are specific to Bitcoin.
newbie
Activity: 7
Merit: 0
@TheWolf666

Thank you for the great guide. I've followed the instructions to make changes and able to build the code on Windows. But I'm unable to start the wallet or the coin daemon server.
It fails in this code, in tx_check.cpp.

Code:
if (tx.IsCoinBase())
    {
        if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 100)
            return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cb-length");
    }

I see that in Chainparams.cpp, there are new variables being set in the latest core code, for example
Code:
consensus.SegwitHeight = 481824;
I've set this to 1 but still no use.

Any pointers? I would like to create a brand new blockchain from start using bitcoin core code for experimental purposes.

Thanks in advance
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
Suggested:
// change the hash of BIPs to your genesis hash (see the genesis section) Huh is your genesis hash
// do it for main, testnet and regnet.
consensus.BIP16Exception = uint256S("0x???");
consensus.BIP34Hash = uint256S("0x???");

=>  you are doing an altcoin so all the BIP should start at Genesis or very early (see my last answer). So, take the hash from your blockchain and yes it should be the same as the assert.

// fix the checkpoint data with your genesis hash, do it for main,testnet and regnet
checkpointData = {{{0, uint256S("0x???")},}};

=> go in your blockchain and add checkpointData = {{{blocknumber, uint256S("hash")},}}; as checkpoint so that if someone change the the blockchain on purpose, the wallets will reject the change. Do it periodically so that you solidify your blockchain against attackers. Add many checkpoints as your blockchain grows, at block 1000, 10000, 50000, 100000, etc...

===========
Suggested: IsNullDummyEnabled has the same problem, do the same to that function.
Question: Cant find it?!! Is it in validation.cpp on the latest bitcoin version?

=> this I do not understand.

===========
Suggested:  Find this “return state.DoS(100, false, REJECT_INVALID, "bad-cb-height", false, "block height mismatch in coinbase");” and comment it.
Question: Cant find it?!! Is it in validation.cpp on the latest bitcoin version?

What I do find is this...

            return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-height", "block height mismatch in coinbase");

=> the genesis block will shoot this error, so you need to comment it in order to have your wallet to mine, or you will not mine.
Also all similar errors due to SEGWITH security tests needs to be commented, at least for the first blocks. SEGWITH needs to check the block before, and there is none for the first blocks... it is impossible to start mining without commenting these.
then you can reinstall all the BIP tests that were blocking the mining, let say at block 1000 for example and change chainparams.cpp accordingly.



===========

member
Activity: 238
Merit: 10
Thanks for this amazing post, im sure it will be useful for those who wants to know how to build their own projects, as for me I don't need it because I'm not qualified to be a blockchain developer or something close, I believe we will only see more scam projects from now on but I'm sure I can avoid getting scam.
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
Suggested:
// change the hash of BIPs to your genesis hash (see the genesis section) Huh is your genesis hash
// do it for main, testnet and regnet.
consensus.BIP16Exception = uint256S("0x???");
consensus.BIP34Hash = uint256S("0x???");

=>  you are doing an altcoin so all the BIP should start at Genesis or very early (see my last answer). So, take the hash from your blockchain and yes it should be the same as the assert.

// fix the checkpoint data with your genesis hash, do it for main,testnet and regnet
checkpointData = {{{0, uint256S("0x???")},}};

=> go in your blockchain and add checkpointData = {{{blocknumber, uint256S("hash")},}}; as checkpoint so that if someone change the the blockchain on purpose, the wallets will reject the change. Do it periodically so that you solidify your blockchain against attackers.

===========
Suggested: IsNullDummyEnabled has the same problem, do the same to that function.
Question: Cant find it?!! Is it in validation.cpp on the latest bitcoin version?

=> this I do not understand.

===========
Suggested:  Find this “return state.DoS(100, false, REJECT_INVALID, "bad-cb-height", false, "block height mismatch in coinbase");” and comment it.
Question: Cant find it?!! Is it in validation.cpp on the latest bitcoin version?

What I do find is this...

            return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-height", "block height mismatch in coinbase");

=> the genesis block will shoot this error, so you need to comment it in order to have your wallet to mine, or you will not mine.
Also all similar errors due to SEGWITH security tests needs to be commented, at least for the first blocks. SEGWITH needs to check the block before, and there is none for the first blocks... it is impossible to start mining without commenting these.
then you can reinstall all the BIP tests that were blocking the mining, let say at block 1000 for example and change chainparams.cpp accordingly.



===========
full member
Activity: 312
Merit: 111
for the hash creation I finally got it using this script;
https://github.com/liveblockchain/genesisgen

Just remember to use Byteswapped as merkelhas! It toke me almst 2 days to find out what I was doig wrong Grin



I got finally the wallet running and adjusted all the other params... But need some info on the instructions mentioned below and would be great if you could give some explanations. I do program in php, python and java but not a C++ guru.. so bear with me Smiley

=========
Suggested:
// change the hash of BIPs to your genesis hash (see the genesis section) Huh is your genesis hash
// do it for main, testnet and regnet.
consensus.BIP16Exception = uint256S("0x???");
consensus.BIP34Hash = uint256S("0x???");

// fix the checkpoint data with your genesis hash, do it for main,testnet and regnet
checkpointData = {{{0, uint256S("0x???")},}};

Question: Do you mean the same hash that also should be used here;
        assert(consensus.hashGenesisBlock == uint256S("000000002737f91027590faddd70434f10ac4d0bc673f4134e2d7671ae7d7a86"));

or is it something else?

===========
Suggested: IsNullDummyEnabled has the same problem, do the same to that function.
Question: Cant find it?!! Is it in validation.cpp on the latest bitcoin version?

===========
Suggested:  Find this “return state.DoS(100, false, REJECT_INVALID, "bad-cb-height", false, "block height mismatch in coinbase");” and comment it.
Question: Cant find it?!! Is it in validation.cpp on the latest bitcoin version?

What I do find is this...

            return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-height", "block height mismatch in coinbase");

===========
full member
Activity: 312
Merit: 111
Solved using another genesis creator script
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
Use this to mine the genesis block

Code:
static void MineGenesis(CBlockHeader &genesisBlock, const uint256 &powLimit, bool noProduction) {
    if (noProduction) genesisBlock.nTime = std::time(nullptr);
    genesisBlock.nNonce = std::time(nullptr);

    printf("NOTE: Genesis nTime = %u \n", genesisBlock.nTime);
    printf("WARN: Genesis nNonce (BLANK!) = %u \n", genesisBlock.nNonce);

    arith_uint256 besthash;
    memset(&besthash, 0xFF, 32);
    arith_uint256 hashTarget = UintToArith256(powLimit);
    printf("Target: %s\n", hashTarget.GetHex().c_str());
    arith_uint256 newhash = UintToArith256(genesisBlock.GetHash());
    while (newhash > hashTarget) {
        genesisBlock.nNonce++;
        if (genesisBlock.nNonce == 0) {
            printf("NONCE WRAPPED, incrementing time\n");
            ++genesisBlock.nTime;
        }
        // If nothing found after trying for a while, print status
        if ((genesisBlock.nNonce & 0xffff) == 0)
            printf("nonce %08X: hash = %s target=%s \r",
                   genesisBlock.nNonce, newhash.ToString().c_str(),
                   hashTarget.ToString().c_str());

        if (newhash < besthash) {
            besthash = newhash;
            printf("New best: %s\n", newhash.GetHex().c_str());
        }
        newhash = UintToArith256(genesisBlock.GetHash());
    }
    printf("\nGenesis nTime = %u \n", genesisBlock.nTime);
    printf("Genesis nNonce = %u \n", genesisBlock.nNonce);
    printf("Genesis nBits: %08x\n", genesisBlock.nBits);
    printf("Genesis Hash = %s\n", newhash.ToString().c_str());
    printf("Genesis Hash Merkle Root = %s\n", genesisBlock.hashMerkleRoot.ToString().c_str());
    printf("Genesis Hash Merkle Root = %s\n", genesisBlock.hashMerkleRoot.ToString().c_str());
}

call like this

Code:
        genesis = CreateGenesisBlock(std::time(nullptr), 546521654, 0x1d00ffff, 1, 50 * COIN);
        MineGenesis(genesis, consensus.powLimit, true);

Then change the asserts with the merkel and hash generated by this algo. It will work on the latest version of Bitcoin core.
full member
Activity: 312
Merit: 111
to give an update, this coode doesnt work on the latest bitcoin version;

hashGenesisBlock = uint256("0x01");
if (true && genesis.GetHash() != hashGenesisBlock)
        {
            printf("recalculating params for mainnet.\n");
            printf("old mainnet genesis nonce: %d\n", genesis.nNonce);
            printf("old mainnet genesis hash:  %s\n", hashGenesisBlock.ToString().c_str());
            // deliberately empty for loop finds nonce value.
            for(genesis.nNonce == 0; genesis.GetHash() > bnProofOfWorkLimit; genesis.nNonce++){ }
            printf("new mainnet genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
            printf("new mainnet genesis nonce: %d\n", genesis.nNonce);
            printf("new mainnet genesis hash: %s\n", genesis.GetHash().ToString().c_str());
        }


It gives erros;
full member
Activity: 312
Merit: 111
or you can just use ark deployer, in a few clicks you would get a working blockchain/altcoin,
https://ark.io/deployer

soon it will just one click,
https://deployer.io/

And whats the point of doing that? I try to build, learn and test, not using some past© click & done chain. If you cant help with the code above, don’t bother spamming.
legendary
Activity: 1764
Merit: 1000
or you can just use ark deployer, in a few clicks you would get a working blockchain/altcoin,
https://ark.io/deployer

soon it will just one click,
https://deployer.io/
full member
Activity: 312
Merit: 111
Hi, I try to create a new alt from btc code to test couple of things, but somehow I am missing something. I think I can get the genessis block created as assert dont give me any error anymore but I still get the error below;
ERROR: ReadBlockFromDisk: Errors in block header at FlatFilePos(nFile=0, nPos=8)

I think that there is something about the nNonce or minimum difficulty that gets in the way.
copper member
Activity: 154
Merit: 0
IMO Exchange - Customer First.
The wonders of blockchain technology, anybody can just suddenly wake up and print money out of thin air and when they have the right connections and contacts, even get people to invest in it, a nice guild anyways, even if it might empower scammers.
newbie
Activity: 5
Merit: 0
Very nice guide OP thank you. I was wondering if you perhaps had any scripts that can generate the genesis for Litecoin? Struggling like mad to get the latest core of LTC going. Tried every code i could find but keeps giving assertion errors.

Thank you
newbie
Activity: 24
Merit: 3
Brilliant guide. thank you. I learned a lot !

I wondered if you could point me in the direction of a solution for my only major hurdle...

When using Yiimp, no matter if its on an Azure VPS in France with all ports set up, or an Ubuntu server on my home network, I cannot seem to get the new coin wallet to "connect" to a Yiimp wallet.

Beneath the Difficulty/ Blocks / Balance .. I get "ERROR Connection timed out after 20000 milliseconds"


Coin config correct with rpc data + server/daemon/listen=1 and definitely restarted and running daemon with 'deprecatedrpc=accounts -printtoconsole'

Also - when I run the stratum script with sha config I get a "dead lock" error loop:

20:46:40: 2019-07-22 starting stratum for sha256 on ubuntuserver18:3333
20:47:17: 2019-07-22 sha256 dead lock, exiting...

Am I missing something super Obvious!? The web server works well and wallets all connect perfectly so the network is good.


nevermind I found out bitcoin 18.99 has many reasons why the stratum part will not work well with yamp.
I'm going to clone bitcoin 16 and start over which I think will work better.
Thanks again for this brilliant guide.
member
Activity: 574
Merit: 18
Making Smart Money Work
This is a very good tutorial that shouldn't get to the wrong hands ,youve just given those who wants to scam but don't know how a chance and I bet many crap project will be released in the announcement section soon ,I have no reason to create new altcoin when i have nothing to offer im here to invest in very good altcoins only but thanks
newbie
Activity: 8
Merit: 1
Most complete and updated guide I have found so far... kudo on the job mate.
sr. member
Activity: 517
Merit: 257
CryptoTalk.Org - Get Paid for every Post!
Nice little guide but dangerous!! Here comes some more crap in the announcement section  Wink
sr. member
Activity: 2226
Merit: 347
I am not related to the 2018 tutorial at all.
Bitcoin has changed with version 0.17 and a lot of problems are not published anywhere.
Making a coin ask some programming knowledge. Even if you are using a tutorial, you cannot do a functionnal coin without understanding what you are doing.
It is like an IQ test of some sort.
But I have been blocked by stupid issues that I would have loved to find a solution online. Debuging peer to peer is really complex, and some bugs do not give you any clue about where they are coming from.
For example when a transaction is flagged by a peer, but not by another peer!

So I guess this tutorial removes the obvious mistakes, but you have to be sharp to get to the final line. Smiley

How are you related to this thread? https://bitcointalksearch.org/topic/complete-guide-on-how-to-create-a-new-alt-coin-update-2018-3345808 . Same topic title and same template and by the way i do appreciate your effort on posting it up
on creating a new altcoin but im not really fully agree that these tutorials would be post up yet there are people who would just tend to make use of this tut and create his own shitcoins piling up on
the entire market.
Okay that cleared out my mind and also i fully agree into this point you said on OP.

Quote
Many people around are offering alt coin based on templates. First, be careful as a Trojan can be hidden very easily and you might lose all your work if you deal with the wrong people. Then most of the time they are using outdated versions of Bitcoin core, Litecoin that is based on outdated Bitcoin core, Dash that is based on outdated Bitcoin core etc… basically they are using version with solo-mining or RPC mining enabled, avoiding the real problems. If you are doing that, you are going to get an obsolete coin that will never be trusted, and it is just a matter of time until investors realize that, and sell.

Common mistake to be missed out.

Im not really knowledagable on programming skills but i do have some sort of idea which i can still possibly follow up those things being post up above thats why i appreciate it.
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
I am not related to the 2018 tutorial at all.
Bitcoin has changed with version 0.17 and a lot of problems are not published anywhere.
Making a coin ask some programming knowledge. Even if you are using a tutorial, you cannot do a functionnal coin without understanding what you are doing.
It is like an IQ test of some sort.
But I have been blocked by stupid issues that I would have loved to find a solution online. Debuging peer to peer is really complex, and some bugs do not give you any clue about where they are coming from.
For example when a transaction is flagged by a peer, but not by another peer!

So I guess this tutorial removes the obvious mistakes, but you have to be sharp to get to the final line. Smiley

How are you related to this thread? https://bitcointalksearch.org/topic/complete-guide-on-how-to-create-a-new-alt-coin-update-2018-3345808 . Same topic title and same template and by the way i do appreciate your effort on posting it up
on creating a new altcoin but im not really fully agree that these tutorials would be post up yet there are people who would just tend to make use of this tut and create his own shitcoins piling up on
the entire market.
sr. member
Activity: 2226
Merit: 347
How are you related to this thread? https://bitcointalksearch.org/topic/complete-guide-on-how-to-create-a-new-alt-coin-update-2018-3345808 . Same topic title and same template and by the way i do appreciate your effort on posting it up
on creating a new altcoin but im not really fully agree that these tutorials would be post up yet there are people who would just tend to make use of this tut and create his own shitcoins piling up on
the entire market.
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
Introduction

I am the author of the Kryptofranc ... you will hear about them very soon. https://kryptofranc.com
I have spent the time to adapt the latest Bitcoin Core development to my own fully functional blockchain and on the way of doing it, I have found that a LOT of things in the previous guides posted on the net were lacking of update or were totally obsolete.
Therefore, I have decided to update these guides to my own sauce, and I hope it will save time for the newbies, and update the legendary programmers to the latest roadblocks the Bitcoin core team have left for us recently.


1) Choice of Bitcoin Core 0.18 (mostly still works with 0.20)
This is the most updated and dynamic development out there. Almost all the good ideas from other coins are ending up in the Bitcoin core source one day or another, and usually with a better implementation.
Take Sigwit, pruning, HD address, privacy, lightning network; Bitcoin Core does it all.
However, the Bitcoin core team seems to try to make it impossible to create an alt coin from their core, by removing the solo mining first, then the RPC mining, and by adding plethora of tests for “security” but that are blocking new coins to mine when they are at the genesis state.
This guide will sort out all these problems.
2) Do not expect it to be easy.
Many people around are offering alt coin based on templates. First, be careful as a Trojan can be hidden very easily and you might lose all your work if you deal with the wrong people. Then most of the time they are using outdated versions of Bitcoin core, Litecoin that is based on outdated Bitcoin core, Dash that is based on outdated Bitcoin core etc… basically, they are using a version with solo-mining or RPC mining enabled, avoiding the real problems. If you are doing that, you are going to get an obsolete coin that will never be trusted, and it is just a matter of time until investors realize that, and sell.
3) Do not blame me for errors
If you find an error, tell me and I will fix it. Let us collaborate. I am writing this guide quickly, it is a complex subject so, be kind and complete the missing points if you find some.
4) Give credit to this page with a link if you copy this post to your blog.


Setting Up

a)   You will need two Unix instances to create a functional coin that will also mine.
Server 1: Mining wallet and development server.
Server 2: Second node and receiving wallet.
I suggest purchasing a dedicated server at Hetzner. Their auctions have the best value for the price (I am not related to them, you can use any ISP) : https://www.hetzner.com/sb
For 21 Eur you can get a 9000 Benchmark server. Don’t take an Atom that will take forever to compile. Get 2 instances for about 42 Eur.

b)   Get an account at Github, and fork the latest Bitcoin core version (0.18 here).

c)   Install the latest Ubuntu on both servers. Install Mate to have a graphic interface that is fast. Do that on both servers.
Code:
sudo apt install ubuntu-mate-desktop

and XRDP
Code:
sudo apt install xrdp
sudo systemctl enable xrdp
Now you can login with Remote Desktop from your local windows.
Install Clion to edit your C++ code with ease. You get 1 month free, enough for your development. This development tool is worth every penny, specially for its search that will save you a lot of time.
   
Code:
https://www.jetbrains.com/clion/download/#section=windows

d)   On server 1 install Yiimp by using this script: https://github.com/xavatar/yiimp_install_scrypt_ubuntu18.04 or use my backup on my repository, it is working and clean https://github.com/NicolasChoukroun/yiimp_install_scrypt_ubuntu18.04
Also be cautious, some people are offering to install Yiimp for you but they also install a backdoor and get a fee from every mining, I got this problem and I had to do everything myself to get rid of it. So beware the “services”. Do it yourself!
Now you are ready to modify Bitcoin Core to your flavor, do it on server 1. Server 2 will compile the result and run a second node when you have finished.
Yiimp will be used to mine the coin, do your premine and also as a block explorer.


Bitcoin Core modifications.

a)   Directory structure.
Use this structure.
Yourcoin/Yourcoincore/
In /Yourcoin/ put everything that needs to be out of the Bitcoin Core source code, your scripts, assets, pictures, translation scripts etc…
In /Yourcoin/Yourcoincore/ dump the Bitcoin source code that you have forked
Save that result to your own GitHub so that when you make a mess, you can clone and start again.
You can also use this script to automatically compile your coin and the dependencies. Note that this script solves some compilation issues for windows that many seems to be unaware of.
https://github.com/NicolasChoukroun/BitcoinMaker
Usage is included in the script just run ./maker.sh and see.
At this point, you need to compile Bitcoin: https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md
Or
Code:
./maker.sh unix install
./maker.sh unix all

Don’t go further until Bitcoin is launching on your machine.

b)   Creation of the certificates (optional)
You can keep the Bitcoin certificates, but it is better to have your own for the strength of your blockchain.
Code:
openssl ecparam -genkey -name secp256k1 -text -noout -outform DER | xxd -p -c 1000 | sed 's/41534e31204f49443a20736563703235366b310a30740201010420/PrivKey: /' | sed 's/a00706052b8104000aa144034200/\'$'\nPubKey: /'


Replace the result in chainparams.cpp here:
Code:
const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;

And change your passphrase here with what you want:

Code:
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
Remember to keep it short, I think that the length is limited to 150 characters, so do not write a book or you will get an error.

c)   Creation of the genesis.
In order to have your own blockchain, you need to have your own genesis. This step is explained in many tutorials; it should not be a problem.

I have made my own function based on what I have found in another altcoin, you can get the code here:
https://github.com/NicolasChoukroun/altcoin-genesis

You need to copy the code as explained in the readme and you will get the nTime, nNone, nBits, Hash and Merkle Root (inverted).

You can now replace these in chainparams.cpp, in 3 places, in “main”, “testnet” and “regnet”.

Code:
	genesis = CreateGenesisBlock(nTime, nNonce, 0x1d00ffff, 1, 50 * COIN);

Also change the asserts with the Hash and Merkle Root you got from the genesis. Do it 3 times for main, testnet and regnet.

Code:
assert(consensus.hashGenesisBlock == uint256S("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
        assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));

Compile and run the wallet, see if you get an assert error. If you have, you made a typo.

d)   Change all Bitcoin core mentions with your altcoin name.
This is tricky as Bitcoin is all over the place. I cannot help too much; I personally use PHP to do it. You need to scan all the files with conditions to avoid replacing code. Show your scripting skills here.

e)   Change the graphics
/src/qt/res/ there are icons and graphics, replace them with the one from yourcoin.

f)   Customize chainparams.cpp
This file has things to change to personalize your coin, so I will make a list to get this done quickly. Read the comments in the following code.

Code:
// change all the pchMessageStart with something else, so that your messages are unique.
pchMessageStart[0] = 0xf9;
pchMessageStart[1] = 0xbe;
pchMessageStart[2] = 0xb4;
pchMessageStart[3] = 0xd9;

// change the default port, choose one port that is not used by another popular prog like ftp, or emails. Choose a different port for main,testnet and regnet.
nDefaultPort = 8333;

// change this to this value so that the consensus will accept your low difficulty mining at starting.
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000000000000000100010001");

// start all the PIB from height 1, so change these to 1
consensus.BIP34Height = 1;
consensus.BIP65Height = 1;
consensus.BIP65Height = 1;

// change the hash of BIPs to your genesis hash (see the genesis section) ??? is your genesis hash
// do it for main, testnet and regnet.
consensus.BIP16Exception = uint256S("0x???");
consensus.BIP34Hash = uint256S("0x???");

// fix the checkpoint data with your genesis hash, do it for main,testnet and regnet
checkpointData = {{{0, uint256S("0x???")},}};

// empty ChainTxData like this
chainTxData = ChainTxData{};

// you can change how often the wallet will retarget the difficulty.
consensus.nPowTargetTimespan =   14 * 24 * 60 * 60; // two weeks

// you can change the target for coin generation; bitcoin is 10 minutes, litecoin 2.5 minutes. Short means quicker transactions, but also more risk of orphan and failed transactions due to network issues.
// Also the faster, the more inflation, take this in account when you calculate your max coin generation, and rates.
consensus.nPowTargetSpacing = 10*60;

// blockchain size: your blockchain is very small; change this parameter to 1 so that it will not ask too much space at starting.
m_assumed_blockchain_size = 1; // was 240

// comments all the vSeeds, and change that to your server 1 and server 2 address since they will run the wallet and need to be peer to each other to get your coin to be functional.
vSeeds.emplace_back("seed.bitcoin.sipa.be");
vSeeds.emplace_back("dnsseed.bluematt.me");

// change the prefixes to your coin. If your coin is named Yourcoin for example you want that prefix to be Y
// prefixes are not that obvious, check https://en.bitcoin.it/wiki/List_of_address_prefixes
// to understand how prefixes are calculated
base58Prefixes[PUBKEY_ADDRESS] = std::vector(1,0);
base58Prefixes[SCRIPT_ADDRESS] = std::vector(1,5);
base58Prefixes[SECRET_KEY] =     std::vector(1,128);

// change this to something of your own
bech32_hrp = "bc"; // change to yc for yourcoin for example?

That’s it for chainparams.cpp. Remember to do these changes for all the networks, main, testnet and regnet

g)   Customize validation.cpp
Mostly validation deals with subsidy and validity checks. Subsidy defines how many coins are created when the proof of work submitted by a miner is accepted. This is the reward formula. This is where you will do your premine.
There are some traps not to fall into here. nSubsidy is a CAmount (int64_t), it is not a float. So be sure that with your calculation, you will not have a divide by zero!

Here is an example that is functioning. Note the +1 to avoid having 0 divides. I also add a debug to console so that the subsidy can be witnessed from the console.

In that code, you can see that we premine 120000 coins to 6 wallets. The method is as follow.
At height 10, 50, 70, 90, 110 and 130 we will mine 20000 coins. The blocks in between are here to allow the time to get the mined coins to maturity, then send the coins from server1 wallet to server2 wallet, then mine more to allow the transaction to be confirmed. Once this done you can encrypt the server2 wallet, backup it, remove the .yourcoin directory and restart the wallet with a fresh new address
This way you can premine and save in different wallet to distribute to your team, friends, investors.
Once the premine is done, the script will delivers 63/halfing coins every coin mined.
Note that this algorithm is not waiting 2 years to adjust like Bitcoin, it adjust every coin mined. You might change it to your liking.

Code:
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams) {
    CAmount nSubsidy;
    if (nHeight == 10 || nHeight == 50 || nHeight == 70 || nHeight == 90 || nHeight == 110 || nHeight == 130)  {
        nSubsidy = 20000*COIN;   // premine 6x20000 coins
    } else {
        if (nHeight <= 150) {
            nSubsidy = 10 * COIN ;  // small mining to carry out the transactions
        } else {
            float year= (nHeight / 210240)+1; // avoid to get a negative nSubsidy
            float halfing =  year/ 1.618033988750;
            nSubsidy = (63 / halfing)*COIN;
        }
    }
    printf("GetBlockSubsidy: height: %i - nSubsidy: %ld \n",nHeight, nSubsidy);
    return nSubsidy;

}

Validation.cpp is not finished yet. We have a problem with SEGWIT. It cannot work at height 1. So in the beginning, we need to disable some checks, that will have to be re-enabled when the blockchain has at least 2000 blocks mined. You have to experiment here; the goal of this tutorial is not to deal with the blockchain maintenance.

bool IsWitnessEnabled needs to return true in all cases. So just add return true; at the beginning of the function.

IsNullDummyEnabled has the same problem, do the same to that function.

Find this “return state.DoS(100, false, REJECT_INVALID, "bad-cb-height", false, "block height mismatch in coinbase");” and comment it.

End of the validation.cpp customization.

h)   Other code modifications.
There are more modifications, spread everywhere that needs to be fixed in order to get the coin to work correctly.

validation.h  :
-   you need to change the DEFAULT_MAX_TIP_AGE to something very large (60*60*24*365 for example). This is temporary. This is the interval when the blockchain is not mining. At starting you might have a genesis made long time ago, and not have mined for a while, so that this has to be changed or your Coin will not work.
-   DEFAULT_CHECKPOINTS_ENABLED = true; needs to be changed to false, or your coin will try to verify that you are on the Bitcoin blockchain, which you are not.

\rpc\mining.cpp :
Another SEGWIT test that needs to be removed:

Code:
throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the segwit rule set (call with {\"rules\": [\"segwit\"]})");
Comment this line.

net_processing.cpp :
-   STALE_CHECK_INTERVAL need to be changed to a large value to avoid having a STALE error, this is again temporary, once the blockchain is mined by many people, it can be back to the original values. (3600*24*365 for example)
-   STALE_RELAY_AGE_LIMIT same for this static variable.

\qt\bitcoingui.cpp
Get rid of the loading form set this variable to 0.

Code:
qint64 secs = blockDate.secsTo(currentDate);
becomes qint64 secs=0;

Now you should have a functional Coin. But you need to mine.


------------------------------------------------------------------------------------------------------------------------------------------

Mining with stratum and Yiimp


a)   Modification of stratum.
In order to mine your coin, you need to use Yiimp that you have installed previously.
But the latest version won’t work with a “virgin” coin at block zero so here is how to fix that.
First, you need to setup your coin by following this tutorial:
https://www.boostrend.com/2018/03/how-to-setup-new-coin-wallet-on-pool.html

The most important things are:
-   Run your coin wallets by using the code given in the coin settings of Yiimp, but don’t forget to change the path since the installation script install stratum in /var/stratum. blocknotify=/var/stratum/blocknotify pool.kryptofranc.net:3333 1455 %s
for example is what is working for me.
-   Run your coin by using the following command line: yourcoin-qt –deprecatedrpc=accounts -printtoconsole
-   Type getnewaddress in the console on server1: enter this address everywhere an address is asked in the coin definition of Yiimp backend.
-   Compile and run your coin on server2
-   Type getnewaddress in the console of server2 to get an address to send to from the mining wallet.
-   Download ccminer (version 230 is working for me) for windows and edit a config file to match your coin definition, for example: ccminer.exe -a bitcoin -o stratum+tcp://pool.yourcoin.com:3333 -u xxxyourserver2addressxxx -p c=KYF
replace xxxyourserver2addressxxx with the address you got from your server2.
-   Run stratum on server1 (/var/stratum/run.sh sha)
If ccminer cannot mine, then you can use my fixed version here: https://github.com/NicolasChoukroun/stratum
Use it at your own risk, it is working for me, but who knows?
What needs to be fixed in Stratum is in coind.cpp function coind_can_mine, there are several tests of (!coind->height) which are not working for us since we are at block 0. This needs to be changed to

Code:
If (!coind->height)
// change to
if (coind->height<0)

My version also adds a lot of real-time comments to help debug stratum.
The coin must be set to auto ready, enabled, and difficulty must be >0

Mission accomplished! Now you have a fully working coin, which can mine though stratum.

------------------------------------------------------------------------------------------------------------------------------------------

DISCLAIMER
This tutorial may contain technical or typographical errors.
I do not guarantee its accuracy, completeness, or suitability.
IN NO EVENT SHALL I BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES RELATING TO THIS TUTORIAL, FOR ANY USE OF THIS TUTORIAL.
I take no responsibility and makes no warranty whatsoever from the use of this tutorial linked to or from this tutorial.
IT IS DELIVERED ** AS IS **.
ANYONE USING THIS TUTORIAL IS DOING IT AT HIS/HER OWN RISKS.

Jump to: