Blockchain technology from 0 to 1 to build their own development of counterfeit coins

Source: Internet
Author: User
Tags assert openssl pow unique id port number git clone

Blockchain Enthusiast (qq:53016353)

Since 2009 Satoshi Nakamoto released the Bitcoin of open source projects, blockchain technology as the supporting technology behind it is also slowly developing, since 2014, more and more technology giants and industrial capital gradually entered the field, The development of blockchain technology has also played a significant role in promoting.

We can think of Bitcoin as the first financial application based on blockchain technology, a monetary system and payment clearing network that is centralized, does not have to trust individual nodes, is private and transparent, is maintained by everyone under the consensus mechanism. Such a centralized clearing network is becoming another infrastructure for the internet, just as computing power and bandwidth are the infrastructure of the Internet, and Bitcoin's payment network is becoming another kind of internet infrastructure-"trust", an infrastructure that is maintained by miners around the world every day, And more and more fascinating magic, and become a hotbed of Fintech innovation and infrastructure, but also attract more and more resources into the field.


In addition to application in the field of payment and finance, blockchain, as a centralized, shared, open and transparent digital ledger that does not require a single node to be trusted, is also being used in many fields such as the Internet of things, identity authentication, supply chain management, copyright management, and centralized application. Blockchain technology solves the problem of the famous "Byzantine generals" in the computer field, which makes it possible to create a centralized consensus network without trusting a single node.


At present, most of the projects related to blockchain technology are abroad, the development and application of domestic blockchain technology lags behind, so we plan to write some simple development manuals in our spare time, hoping to help individuals or small companies in this industry.


The tentative writing plan is divided into two parts.


Part one: "From 0 to 1, build your own blockchain": relive the launch process of the Bitcoin network and issue its own blockchain network (private chain)


The second part: "From 0 to 1, development zone block chain application": On the public chain and the private chain, to develop their own blockchain applications.


Part I: Create your own blockchain directory from 0 to 1:


1.1 Starting from imitation, the first knowledge of the blockchain
1.2 The basis of blockchain: an analysis of the consensus mechanism
Design principle and design method of 1.3 consensus mechanism
1.4 How to quickly clone a blockchain
1.5 How to turn Bitcoin into your own private chain – fork Bitcoin
1.6 How to turn Ethereum into your own private chain – fork Ethereum
1.7 How to turn Ripple into your own private chain – fork Ripple
1.8 How to turn stellar into your own private chain – fork stellar 1.9 How to build a mine pool and dig out your own founding blocks
1.10 How to develop your own blockchain wallet (Windows and MAC) 1.11 How to develop your own blockchain wallet (Android and IOS) 1.12 How to develop an online wallet similar to Blockchain.info 1.13 How to add your own blockchain network to the Ann Full and robust 1.14 how to use Coind to handle top-up and withdrawal services
1.15 How to use the pool to build a mixed-currency service
1.16 How to design a new mining algorithm





1.1 Starting from imitation, the first knowledge of the blockchain



For science and engineering people, the best way to learn is to get started directly, the concept of blockchain we know a lot, today let us unlock the mystery of the blockchain, let us work directly, let us start from scratch to release their own blockchain, and in the release process to learn!


The current mainstream consensus mechanism is pow,pos,dpos, there are ripple and stellar consensus agreement, and Ethereum consensus agreement, and so on, in fact, there are some altcoin there are some unique consensus agreement, the current concern of less people (these consensus agreements, We will analyze it in detail later).


Imitation needs a source, considering the Bitcoin source after 6 years of iteration, and the original version has a big difference, we choose Sunny King God's POS protocol as the basis to publish their own blockchain, here we choose a good code base on GitHub: Craveco In's original code server configuration: Alibaba Cloud leased Ubuntu14.04 version server 2Core 4GB login server root@your password
Download the sample source code from GitHub:




Where Crave.pro is the file doc required for QT client compilation


is some basic docs, included in the source code


Share have some needed libs build ' s used by the build system so we always need it


SRC contains the source code required for client compilation, as well as images and logos


Pro file for the client to compile the required files, on Alibaba cloud Ubuntu14.04 above, we can compile the Linux wallet client and the Windows wallet client


In order to alive our own blockchain, we need to replace the CRAVE blockchain with our own blockchain, because Neo is the embodiment and spokesperson of the "Thematrix" Justice, we publish a blockchain blockchain for Neo.


Snip20151109_26


We renamed Crave.pro to Neocoin.pro (here you can rename any name you like, such as Xcoin or Bankcoin. Or your company coin)


From the POS2.0 protocol, the parameters of the blockchain network are stored in the Chainparams.cpp, in the most original POS source code, the network parameters are stored in main.cpp and Main.h, from 2014 onwards, the mainstream POS protocol in this way.


Nano chainparams.cpp Open Chainparams.cpp file


The most important thing to modify a blockchain is to modify the Pchmessage, followed by a 16 binary identifier, which is an ID of the blockchain that distinguishes two different blockchain chains. Otherwise, if you do not modify it, your own blockchain will be synced to the other block chain. The source code is:


CHMESSAGESTART[2] = 0x05;
CHMESSAGESTART[2] = 0xa5;
CHMESSAGESTART[2] = 0xb6;
CHMESSAGESTART[2] = 0x1b;
Where 0x remains the same, the number range 0-6, the letter range A-f we modified to:


Pchmessagestart[0] = 0xaf;
PCHMESSAGESTART[1] = 0x25;
PCHMESSAGESTART[2] = 0x04;
PCHMESSAGESTART[3] = 0x32;
Now we have a unique ID for our blockchain.
Const char* Psztimestamp = 8 Mar The rebirth starts. This is usually used to record the big thing that happened on the day of the blockchain alive, do you know what Satoshi wrote here?


You guess?


Next we need to modify txnew.ntime = 1426700641; How does this time get?
Txnew.ntime represents the Unix time of the blockchain release, where it can be converted to Unix time




Also need to modify Genesis.ntime = 1446708703


Change genesis.nnonce = 17113 to Genesis.nnonce = 0 block starting from 0, Nnonce is used to calculate, calculate the number of blocks needed to find the first block, once the original block is found, the block will be re-counted


Next we need to remove the old Genesis block and the value of the Merkle (remove the older Genesis and Merkle), which is:


ASSERT (Hashgenesisblock = = uint256 ("0x00000a336bf3e2be21c2ce9a3f9bc9849$
ASSERT (Genesis.hashmerkleroot = = uint256 ("0x281554338b643722b01ea689ab6$
We delete unit256 ("0x content, when we compile the first time, will error. A new value is generated in the Debug.log, and the new value is placed in the place.


Then we modify Nlastpowblock = 10000; Represents the last block of POW, where the values can be chosen by themselves, depending on the length of the mining time. But if the value is too small, it will be coin not mature, thus unable to stake, as the network stagnation. I changed it to 1000 here.


Also in the Chainparams.cpp file, you can find a testnet and modify the blockchain identifier in the Testnet


Pchmessagestart[0] = 0x1f;
PCHMESSAGESTART[1] = 0x22;
PCHMESSAGESTART[2] = 0x05;
PCHMESSAGESTART[3] = 0x30;
In Bitcoin's testnet network, we can test some of the new BIP protocols, such as we can set the chunk size to 20MB to see how the network is running. On top of your own private chain, we can test any feature we want. Without interfering with the mainnet or destroying the integrity of the mainnet.


Also modify Testnet's Genesis block assert (Hashgenesisblock = = uint256 ("0x00000a336bf3e2be21c2ce9a3f9bc9849$ Delete value after 0x


In source Valertpubkey is also very critical, can increase the security of the network, can be used to notify the new block, in our first run daemon time, will produce a network of Publickey,publickey can be generated by checkpoint Yes.


Below we modify the port number of the network


Ndefaultport = 30104; For the peer port, the network is used to communicate with daemons


Nrpcport = 30105; For RPC ports, all Exchange,pool, explorer via RPC port with daemon communication can be modified to any port number 10000 to 60000, we modify to 26666 and 26667


Ndefaultport = 26666;
Nrpcport = 26667;
After the modification is complete, Ctrl+x keeps the file and exits.


Then go into the main.cpp and find


unsigned int nstakeminage = 8 60 60; 8 hours
unsigned int nmodifierinterval = 8 * 60; Time to Elaps
Here is the least staketime, in the pos2.0 protocol, we need the mini stake age, which is no longer needed in the POS3.0 protocol. The generic is 8 hours, but you can modify it to any time, usually, for network security, the recommended time is greater than 1 hours. But in the pos3.0 protocol, coin starts from Block1 stake!


int ncoinbasematurity = 188; The number of chunks that are coin mature can be changed to any number. Here, I changed to 100.


int64_t nsubsidy = * COIN; For the amount of the block bonus, you can change the block reward you want here, and of course you can set the block reward structure you want, and control how much the POW and pos coins are.


static const int64_t Ntargettimespan = 24 * 60; The time mins for block difficulty adjustment, usually if is a public chain, at the beginning of mining, we hope that the difficulty coefficient as soon as possible to adjust, can prevent instamine.


int ntargetspacing = 60; For chunk time, Bitcoin here is 600s, we set here to 30s. The time is too short to fork the network easily.


Below we modify the Main.h file


static const unsigned int max_block_size = 40000000; for chunk size, here is 1MB in source code of Bitcoin, we change 40000000 to 20MB, but our network does not More than 1MB ...


static const int64_t Min_tx_fee = 1000; To pay for the transmission of the network, the unit is Cong, if too little, the network may be stagnant.


static const int64_t Max_money = 2000000000 * COIN; The maximum amount for a single send, not total amount


Ok main.cpp Done


We found Checkpoints.cpp.


static Mapcheckpoints mapcheckpoints =
Boost::assign::map_list_of
(0, uint256 ("0x00000a336bf3e2be21c2ce9a3f9bc9849c697475d0de85e201bdc$
For the startup block check points to prevent the network fork, now we do not have this value, waiting for daemon to run for the first time, will produce this value


Const std::string Csynccheckpoint::strmasterpubkey =
Masterpubkey tells the network how to synchronize nodes, for a main node, in the early days of the network, we need to synchronize to main node


Checkpoints tells the network which block a particular hash value belongs to


After the modification is complete, we ctrl+x exit


Then find the version management file Clientversion.h


Define Client_version_major 1
#define Client_version_minor 2
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 0
Representative version number 1.2.0 can be modified to 1.0


Below we will produce, Genesis block, with the following code to produce, the following generation of the code to generate the block, paste under Nnonce
Just in Hashgenesisblock.
Snip20151109_27snip20151109_28


This code will detect if there is a Genesis block, and if not, it will produce a founding block. and to print out the founding block information, we can use it later.
Some of the simplest parameter modifications have been completed, and here we begin to configure the compilation environment.


First need to update Ubuntu system to the latest version Type:apt-get update


Install the build environment: Apt-get install git build-essential libssl-dev libboost-all-dev git libdb5.1++-dev libminiupnpc-dev make zip
which


* Build Essential Package (the most basic thing for a compiled environment)
* Libssl-dev:openssl Need
*libboost:c++ boost libraries for the coin
* libdb5.1: Compiling wallet.dat files requires
MINIUPNPC: Wallet Connection Network needs wallets to look for open ports and connect
Make: Used to compile wallets


After the configuration is complete, we use Make-f Makefile.unix
For the first compilation ... HMM write here, forget one thing there is no ...


Snip20151109_31


We have not modified the name of this private chain have ... Find replacement you wouldn't ... Replace all cravecoin or CRAVE or cravecoin with the name you want ....


We used a super-flashy command: grep-rl ' crave '. Xargs sed-i ' s/crave/neocoin/g ' replacement name also needs your own to replace the crave or cravecoin. Same command with three times


Say our logo I also forgot. Back and replace


After all the replacements are complete, we compile again


Make-f Makefile.unix


Forget that we are a dual-core CPU, we can speed up the compilation


Make-j2-f Makefile.unix


Compile successfully,./neocoind


Genesis.nnonce = 95200 Replace the original genesis.nnonce = 0 with 95200


Get the founding block:


Genesis. Gethash = 00002acaf860e2ae594becc9ce1f20c4714b9aa7fc153f80585d8f562bba5e 1b


Added to Chainparams.cpp and Checkpoints.cpp


After adding, run Neocoind again, this time find Merkle root, before compiling, delete the piece of code used to generate Genesisblock


Run to get Merkle root:8465c95064313d48688e08e19d80915c0e03310a9c85c57d97cb355 c04b31b0e


Below we configure a config file for coind, then run daemon and configure a simple port. If you want to modify the prefix address of public key, you can modify it through the BASE58 encoding table:


./neocoind Stop Stop
./neocoind getaccountaddress ""


Can get an address ncrzs8yirbfmdzza8sqb7ckyeasttdzy8m on another computer also compiled, get a new node, here my node is: ... Open Chainparams.cpp and find
Vseeds.push_back (Cdnsseeddata ("112.74.98.71″," 112.74.98.71″));


Add a node.


Then recompile source, this time we find the network public key and private key. Never leak your network private key. Otherwise people can control the entire network, it is tragic.


After the compilation is complete,./neocoind Makekeypair


Get the PublicKey of the network:


0403dc07ec3f1215b636179659ed7033015cd775baf5fa76c4f70e5d603002d9a261a3adb3bdcbbb8ddb50f19047 5b3a3cd779d2ba0830d770febcd5d7c310d437
Privatekey I'll tell you.


Snip20151109_32


HMM our project has not yet a logo. means that the client does not have a logo. Find a logo here
Snip20151109_33


Let's compile the headache of the Windows development environment, and it is compiled under the Ubuntu system


Directly with the following counter-day command:


Apt-get install \
autoconf automake autopoint Bash bison bzip2 CMake flex \
GetText git g++ gperf intltool libffi-dev libgdk-pixbuf2.0-dev \
Libtool Libltdl-dev libssl-dev Libxml-parser-perl make OpenSSL \
P7zip-full Patch perl pkg-config python ruby scons sed \
Unzip wget Xz-utils
Will download a lot of stuff, what is it. You slowly go to Google, just want to say that Windows is OK. When compiling MAC clients, you will find that there is a large bull.


git clone https://github.com/mxe/mxe.git download cross compiler


Make-j2 QT5 Boost compiles a custom qtversion under Linux needs to be compiled for 3-5 hours


This time I have compiled Mac wallet. Why so fast? Because I've been compiling it.

Snip20151109_34


Cool?


Change the logo inside the/src/qt/res/images/.






Berkley db4.8 used to generate Wallet.dat file


Then modify the path: Export Path=/root/mxe/usr/bin/:${path}; CC=I686-W64-MINGW32-GCC cxx=i686-w64-mingw32-g++


Tell the compilation terminal to use MXE gcc and g++


And then.. /dist/configure–disable-replication–enable-mingw–enable-cxx–host x86_64–prefix=/root/mxe/usr/ i686-w64-mingw32.static/
Configure DB


Then type make starts compiling.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.