Pages:
Author

Topic: Twelve-step program for making yet another stupid altcoin. - page 2. (Read 2969 times)

legendary
Activity: 826
Merit: 1002
amarha
If you want one with scrypt you can fork this: https://github.com/MarkPfennig/pfennig
legendary
Activity: 1330
Merit: 1000
Blockchain Developer
Eh.  I was terse, and a lot of these could be expanded on I guess.  Or made a lot more specific anyway.  But, seriously, the renaming and name replacement gets you 95% of the way there.  Working out how to mine a genesis block held me up for about 20 minutes, but it's simple enough.



you will also want to be replacing left over dev pubkeys, replacing seed nodes & pnseeds, versioning, genesis block generation, clear checkpoints, etc.

Sure you can create an absolute shitcoin with a few commands, but for it to function well you will need to prune the code for leftovers from the old source that won't apply to the new coin. Not too difficult if you know what to look for and where to look.
legendary
Activity: 924
Merit: 1132
Eh.  I was terse, and a lot of these could be expanded on I guess.  Or made a lot more specific anyway.  But, seriously, the renaming and name replacement gets you 95% of the way there.  Working out how to mine a genesis block held me up for about 20 minutes, but it's simple enough.

legendary
Activity: 1330
Merit: 1000
Blockchain Developer
You are missing a lot of steps. Plenty of guides all over the place with the full steps though. Of course shakezulas guide is the gold standard  Cool
legendary
Activity: 924
Merit: 1132
Anybody who knows the windows command line want to fill in with the equivalent commands?  I haven't been using MS systems for a long, long time and don't remember all that.
legendary
Activity: 996
Merit: 1013
This is literally a half hour of work, a dozen or so command lines, and editing one file.  This is what coingen was charging 1 to 5 BTC for?  Man, a whole lot of people got ripped off there.

Not sure, but I think those were based on
older Bitcoin source (0.8?).

What you have just done  is to give to the world a state-of-art
SHA-256 coin cloning tutorial based on most recent release.

And the world thanks you  Cheesy
legendary
Activity: 924
Merit: 1132
I never really realized how ridiculously easy it is to make a clonecoin.  It's literally a matter of about a dozen command lines and editing one file to make a clonecoin that's completely pointless.  Here's how it goes (although the command lines may be different depending on your OS and/or command shell program).

1.  Download and unpack the source of the project you want to clone.  My example will use Bitcoin.

2.  Set up a build environment if you haven't already, and get the build dependencies.

3.  Go to the top directory of the source and type
 find . -type f -print0 | xargs -0 sed -i 's/bitcoin/newname/g' 

to change every instance of 'bitcoin' in the files below that directory to 'newname'.  Repeat, changing 'Bitcoin' and 'BitCoin' to 'Newname', 'BITCOIN' to 'NEWNAME', 'BTC' and 'btc' to 'NEW'.

4.  Because that affected all the files including makefiles that have other filenames in them, and a lot of the files are named 'bitcoin-somethingorother', you need to rename the files to match what's now in the makefile.  So you do that by typing
find . -type f -exec rename 's/bitcoin/newname/
to change all the filenames.

5.  
ls -r | grep -i 'bitcoin'
reveals that no other capitalization matters in the filenames.

6.
ls -r | grep -i 'btc'
will find three files in the 'resources' directory under 'qt' that used 'btc' in their filenames,
    so you need to change those to match the makefiles using
find src/qt/res/ -type f -exec rename 's/btc/NEW/
.

7. Bitcoin uses ports 8332 and 18332 on its main net and 8333 and 18333 on its testnet.  You want to change these to whatever ports you're using for the new coin, so first you type
grep -R 8332
and
grep -R 8333
to look at all the places where those numbers occur in source.  You'll find the port numbers in the source, but the strings also pop up in test vectors in the test directory, which you don't want to change.  So you need to do this in a way that leaves the test directories out of it.  But that's easy, because the places you do want to change it in source are all in the same directory.  So you type
sed -i 's/8332/newnumber1/g' src/*.cpp
and
sed -i 's/8333/newnumber2/g' src/*.cpp
, and that's done.

8. Next thing, you want to change the key prefix bytes so they don't cross up with bitcoin keys. The odds of an accidental collision are ludicrous, but 'odds' and 'accidental' are quaint oldfashioned ideas like thinking that radium suppositories are good for you when working on systems that people will actively attack.  The relevant lines in src/chainparams.cpp for mainparams look like this:
base58Prefixes[PUBKEY_ADDRESS] = list_of(number);
base58Prefixes[SCRIPT_ADDRESS] = list_of(number);
base58Prefixes[SECRET_KEY] = list_of(number);

and the ones in testparams look just like them except for different numbers. So plug in some different numbers so your keys won't be compatible with Bitcoin's system, just to eliminate the possibility of accidental key collisions.  (yes, you're already defaulting to different network ports, and keys are 'random' anyway, so confusion won't happen accidentally - but see the earlier comment about 'accidents' in systems that people will actively attack).  The four-byte sequences in the couple of lines after that are for 'stealth' addresses.   Again, it doesn't really matter what you change them to, unless you want to be cutesy and pick a particular alphanumeric prefix in the base58 representation of your keys.

9. Next up, the network magic bytes.  This is a sequence of four bytes that identify messages as belonging to some particular protocol, that get sent at the beginning of protocol messages.  You want yours to be different than everybody else's, as yet another way to make sure you don't wind up sending a message to (or getting a message from) something else.  Make up (or roll dice to find) some random bytes,  These are the
pchMessageStart[0]
through
pchMessageStart[3]
that get set at the top of CMainParams and CTestParams.  So you edit those to be your new numbers.

10. You probably don't want to show bitcoin's logos and graphics when you start up your alt, so go to the src/qt/res/ directory and change any graphics you find there that you don't want to show, to different graphics.  This is where you change logos and stuff.  I don't know good command lines for this, so you'll probably have to fire up GIMP and do them one at a time.  For now just change them for other graphics with the same size and saved in the same format.  It's a cheap trick, but if you want to do something different, you'll need to learn the qt framework and configure it to load and display something different.

11.  Use
date -+%s
at the command line to find the current time in seconds since the epoch,  add seven thousand or so to it, and plug it into all the parameters blocks replacing all the numbers that match the one that bitcoin's code sets genesis.ntime to.  You can change the
const char* pszTimestamp = 
string too, but keep it under 90 characters. Then insert this code into each of the mainparams and testparams blocks, right after the line that sets HashGenesisBlock:
if ((genesis.GetHash() != hashGenesisBlock) && true)
        {
            Logprintf("recalculating params for mainnet.\n");
            Logprintf("old mainnet genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
            Logprintf("old mainnet genesis nonce: %s\n", genesis.nNonce.ToString().c_str());
            Logprintf("old mainnet genesis hash:  %s\n", hashGenesisBlock.ToString().c_str());
            for(genesis.nNonce == 0; genesis.GetHash() > bnProofOfWorkLimit; genesis.nNonce++){ } // deliberately empty for loop; finds nonce value
            Logprintf("new mainnet genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
            Logprintf("new mainnet genesis nonce: %s\n", genesis.nNonce.ToString().c_str());
            Logprintf("new mainnet genesis hash: %s\n", genesis.GetHash().ToString().c_str());
        }

Then compile it (that's
automake; configure -with-incompabible-bdb; make
in the project's root directory) and start it up.  It'll chew for ~20 minutes to ~2 hours or so figuring out a new nonce and hash, drop them to the logfile, then hit the assert() statement right after that block and crap out immediately.  Then
tail ~/.newcoin/debug.log
will tell you the new parameters.  Plug them in where the code sets nNonce and HashGenesisBlock, recompile, rinse, and repeat for the testnet and regtest initializers.  You will probably want to
rm -rf ~/.newcoin
a few times along the way if you need to recover from any mistakes, and after you have the new parameters plugged in, change those 'true's into 'false's so that the client doesn't just start working on a new genesis block later if it follows a fake chain all the way back to a genesis block that doesn't match.  

12.  Now, still in chainparams.cpp find the line that says
static const Checkpoints::CheckpointData data = {
and delete all those bitcoin checkpoints that come after it.  replace all of them with a single checkpoint at height zero and the hash of your new genesis block.  While you're at it, be sure you have updated the CCheckpointData right after it to your new timestamp.  Also in CCheckpointData you need to set the height of the last checkpoint to zero.  If you're a completist, you'll want to do the same thing (with the new testnet values) at the line that says
static const Checkpoints::CcheckpointData dataTestnet = { 
right after it.   You'll also want to delete all those network seeds and URLs and stuff that are bitcoin-specific; you'd need to put machines up at URLs that are specific to your altcoin to replace them.  Compile one more time.

At this point you have a completely pointless altcoin. Woot.  Big effin' deal.  There are absolutely no new ideas in it.  Also, it has some user-facing strings that will direct people to wrong URLs that you'd want to fix if this were real.  If you launch this as an altcoin, it will fail.  

This is fun if you want to step through the process, mess with it, and change various parameters to see how it works. You can set up a couple machines with this program, point them at each other using the command line 'connect' and  'generate' arguments, and let them mine blocks.  But unless you are someone who has 8 hours a day to spend on supporting it for a long time, some original ideas you want to try out, some network hosting where you can put up long-lived servers to run those address services, and a full understanding of how and why these steps worked, don't mistake yourself for an altcoin dev.  

This is literally a half hour of work, a dozen or so command lines, and editing one file.  This is what coingen was charging 1 to 5 BTC for?  Man, a whole lot of people got ripped off there.
Pages:
Jump to: