Even if I am not in favor of the altcoins' philosophy and I put bitcoin above all, I believe that everyone has the right to create their own cryptocurrency since the code is open source. I personally found difficulties on my way to achieve this. I created tons of threads, but fortunately I made it.
Whoever wants to keep reading and hasn't tried to do this in the past, he'll need Windows 10 and patience. If he doesn't have these two, he can not make altcoin, at least in the way I will describe. The final result will run on windows only. Note that it isn't difficult to run it on linux, but there are just extra steps, which aren't considered needed for a beginner.
First we need to install an Ubuntu terminal to make our lives easier, so you will go to the windows store and download Ubuntu 18.04:
(Once you open it enter a username and a password) Now I will follow the steps of
build-windows.md from github to install some dependencies.
Copy each line below and run it in the terminal:
sudo apt update
sudo apt upgrade
sudo apt install build-essential libtool autotools-dev automake pkg-config bsdmainutils curl git
This may take some time. Then you will clone the source code of the bitcoin core from github. Right after the "bitcoin.git" is the name of the folder that will be created and the name of the cryptocurrency that we will create. In this guide I will use the classic example "altcoin". If you decide to use another name, be sure to change it in every other part of this tutorial.
git clone https://github.com/bitcoin/bitcoin.git altcoin
Once it's done, you'll need to find the bitcoin core files. They will probably be at:
C:\Users\\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\
In the "altcoin" folder the files will look like this:
At the moment we can build them, the problem is that we will make a copy of the bitcoin core that will follow the bitcoin blockchain, something we obviously don't want. We want our own blockchain. The first thing we need to cover is to replace where the word "bitcoin" is with "altcoin". (it is not necessary, but it won't confuse us)
Run these lines:
cd altcoin
find . -type f -print0 | xargs -0 sed -i 's/bitcoin/altcoin/g'
find . -type f -print0 | xargs -0 sed -i 's/Bitcoin/Altcoin/g'
find . -type f -print0 | xargs -0 sed -i 's/BTC/ATC/g'
find . -type f -print0 | xargs -0 sed -i 's/BITCOIN/ALTCOIN/g'
find . -type f -print0 | xargs -0 sed -i 's/BitCoin/AltCoin/g'
(It will take some time)Now that we replaced everything with our cryptocurrency's title, we can't stop. We'll have to rename the files' titles too. Otherwise, it will try to find files that don't exist like "altcoind.cpp". In order to change all titles run these lines:
cd ..
find altcoin -type d -exec chmod 755 {} \;
cd altcoin
find -iname \*.* | rename -v "s/bitcoin/altcoin/g"
Changes in codeWe need to differentiate our blockchain from bitcoin's. Let's start by changing the ports. Go to your files from windows explorer and click on the "src" folder.
In
chainparamsbase.cpp change the
nRPCPort to whatever you want. I suggest to just change the eight e.g.
if (chain == CBaseChainParams::MAIN) {
return MakeUnique("", 2332, 2334);
} else if (chain == CBaseChainParams::TESTNET) {
return MakeUnique("testnet3", 12332, 12334);
} else if (chain == CBaseChainParams::SIGNET) {
return MakeUnique("signet", 32332, 32334);
} else if (chain == CBaseChainParams::REGTEST) {
return MakeUnique("regtest", 12443, 12445);
}
Do the same for the
nDefaultPort of
chainparams.cpp:
nDefaultPort = 2333;
Now we will choose a different signature message in
pchMessageStart of
chainparams.cpp. This is a very important step, if it is not changed and you connect to a bitcoin node it will consider the bitcoin blockchain as the correct one. Do it like this:
pchMessageStart[0] = 0xf0;
pchMessageStart[1] = 0xb0;
pchMessageStart[2] = 0xb0;
pchMessageStart[3] = 0xd0;
Optional, but you can change the address prefix too. (1, 3, bc1)
Link of all prefixes:
https://en.bitcoin.it/wiki/List_of_address_prefixesIn the base58Prefixes of
chainparams.cpp I will show an example of the "X" prefix:
base58Prefixes[PUBKEY_ADDRESS] = std::vector(1,75);
Also optional, you can change the block reward of your currency. In bitcoin it starts with
BTC50 per block.
GetBlockSubsidy at
validation.cpp:
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
// Force block reward to zero when right shift is undefined.
if (halvings >= 64)
return 0;
CAmount nSubsidy = 50 * COIN;
// Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
nSubsidy >>= halvings;
return nSubsidy;
}
I leave it at 50.
We have to set the difficulty equal with 1, since you will be the only miner at the beginning. At
chainparams.cpp change
nMinimumChainWork:
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000000100010001");
In
chainparams.cpp there are some lines that include IP addresses. They're written so you can automatically connect a node(s) once you open Bitcoin Core for the first time (without adding a node with the
addnode "xxx.xxx.xx.xx" add ). So wherever you find a line that starts with
vSeeds.emplace_back delete it. Also, lines that start with
vFixedSeeds must be replaced with:
vFixedSeeds.clear();
There shouldn't be any vFixedSeeds that do something else.
In
chainparams.cpp, we need to change
checkpointData to:
checkpointData = {
{
{ 0, uint256S("0x0")}
}
};
In this tutorial I will not explain how to make our own genesis block, because we want to achieve something simple. Anyone who takes it more seriously can search and learn how it is done. Thus, we need to change the value of
nMaxTipAge in
validation.cpp:
Multiply it with a big number like 10000.
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE * 10000;
In
consensus/consensus.h we need to change
COINBASE_MATURITY which means how "deep" a block must be for the miner to spend its reward. In bitcoin it is 100, that is, someone who will mine 1 block must wait 100 blocks to spend its coins. We can give it any value, I will put it equal with 3:
static const int COINBASE_MATURITY = 3;
Finally, we need to change these two lines of
chainparams.cpp:
m_assumed_blockchain_size = 1;
m_assumed_chain_state_size = 1;
(They are related with the block height in order for nodes to share information)Most notepads change permissions when we mess with LTS. That's why you must run the following lines:
cd src
sudo chmod 640 validation.cpp
sudo chmod 640 chainparams.cpp
sudo chmod 640 chainparamsbase.cpp
cd consensus
sudo chmod 640 consensus.h
cd ..
cd ..
Building.Before we get started we need to install the mingw-w64 cross-compilation tool chain:
sudo apt install g++-mingw-w64-x86-64
When it is finished, we build with the following commands:
PATH=$(echo "$PATH" | sed -e 's/:\/mnt.*//g')
sudo bash -c "echo 0 > /proc/sys/fs/binfmt_misc/status"
cd depends
make HOST=x86_64-w64-mingw32
cd ..
./autogen.sh
CONFIG_SITE=$PWD/depends/x86_64-w64-mingw32/share/config.site ./configure --prefix=/
make
(It may take more than an hour)The files to open the new Altcoin Core are in
altcoin/src/qt:
You can start mining by clicking
window -> console -> generatetoaddress 1 . On
enter something like 1000000000, otherwise you'll most unlikely be able to mine a block. The bitcoin core images can be changed if we had replaced them at the beginning and then went to building.
That was it, now you have created your own coin, but more importantly, your own blockchain. It is worth mentioning that this is for educational purposes only. You obviously can't expect to be the new Satoshi Nakamoto, neither that your coins will have value.
And that's because: There is only one Bitcoin.