第一部分:重命名(本文示例私鍊為: neochain)
1-下載下傳以太坊源碼: download ethereum: https://github.com/ethereum/Go-ethereum/tree/release/1.3.3
2- 重命名代碼:rename folder to go-neochain
3- 重命名相關檔案和檔案夾 rename files and folders:
- replace ethereum with neochain in files and folders filenames
- replace eth with vch in files and folders filenames
4- replace occurences of ethereum in the code (using text replace software like grepWin): 重命名ethereum 代碼中的所有ethereum字元,并替換成neochain,具體替換項目如下:
- repalce github.com/ethereum/go-ethereum with github.com/neochain/go-neochain
- repalce ethereum with neochain in all files
- repalce ETHEREUM with NEOCHAIN in all files
- repalce Ethereum with Neochain in all files
- repalce ether with neochain in all files
- repalce Ether with Neochain in all files
- repalce eth with vch in all files
- repalce ETH with VCH in all files
5- replace back nch_ with eth_ to restore api default functions calls
把eth_替換成nch_,用來存儲調用的API
6- replace back mnchod with method
替換method
7- replace back Mnchod with Method
替換Method
8- replace back wvec with weth to restore the word wheter
替換weth
9- replace default rpc port (we’ll use port 7575):
修改RPC 端口,neochain 利用7575 端口
- in file go-neochain\cmd\utils\flags.go line 71
把以太坊預設端口8545修改成7575
replace: 替換
RPCPortFlag = cli.IntFlag{
Name: "rpcport",
Usage: "HTTP-RPC server listening port",
Value: 8545,
}
with:
RPCPortFlag = cli.IntFlag{
Name: "rpcport",
Usage: "HTTP-RPC server listening port",
Value: 7575,
}
在neochain_js.go 第4108行 也進行替換
- in file go-neochain\jsre\neochain_js.go line 4108
replace: 替換
var HttpProvider = function (host) {
this.host = host || 'http://localhost:8545';
};
with:
var HttpProvider = function (host) {
this.host = host || 'http://localhost:7575';
};
在admin_args.go 第130行也需要進行替換
- in file go-neochain\rpc\api\admin_args.go line 130
replace:
args.ListenPort = 8545
with:
args.ListenPort = 7575
在comms.go 127行也進行替換
in file go-neochain\rpc\comms\comms.go line 127
replace:
if strings.HasPrefix(endpoint, "rpc:") {
parts := strings.Split(endpoint, ":")
addr := "http://localhost"
port := uint(8545)
if len(parts) >= 3 {
addr = parts[1] + ":" + parts[2]
}
with:
if strings.HasPrefix(endpoint, "rpc:") {
parts := strings.Split(endpoint, ":")
addr := "http://localhost"
port := uint(7575)
if len(parts) >= 3 {
addr = parts[1] + ":" + parts[2]
}
替換ethereum的p2p端口,在neochain 中,我們利用17575端口
10- replace default p2p port (we’ll use port 17575):
- in file go-neochain\cmd\utils\flags.go line 315
replace: 替換
ListenPortFlag = cli.IntFlag{
Name: "port",
Usage: "Network listening port",
Value: 30303,
}
with:
ListenPortFlag = cli.IntFlag{
Name: "port",
Usage: "Network listening port",
Value: 17575,
}
替換ethereum的discovery port, 把30301端口替換成27575端口。neochain中我們利用 27575端口。
11- replace default discovery port (we’ll use port 27575):
- in go-neochain\cmd\bootnode\main.go line 37
replace:替換
listenAddr = flag.String(“addr”, “:30301″, “listen address”)
with:
listenAddr = flag.String(“addr”, “:27575″, “listen address”)
第二部分: 修改原始代碼:
1- 停止ethereum的種子節點 disable default seed nodes:
- in go-neochain\vch\backend.go line 71
replace:
defaultBootNodes = []*discover.Node{
// VCH/DEV Go Bootnodes
discover.MustParseNode("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303"), // IE
discover.MustParseNode("enode://de471bccee3d042261d52e9bff31458daecc406142b401d4cd848f677479f73104b9fdeb090af9583d3391b7f10cb2ba9e26865dd5fca4fcdc0fb1e3b723c786@54.94.239.50:30303"), // BR
discover.MustParseNode("enode://1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082@52.74.57.123:30303"), // SG
// VCH/DEV cpp-neochain (poc-9.vchdev.com)
discover.MustParseNode("enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303"),}
defaultTestNetBootNodes = []*discover.Node{
discover.MustParseNode("enode://e4533109cc9bd7604e4ff6c095f7a1d807e15b38e9bfeb05d3b7c423ba86af0a9e89abbf40bd9dde4250fef114cd09270fa4e224cbeef8b7bf05a51e8260d6b8@94.242.229.4:40404"),
discover.MustParseNode("enode://8c336ee6f03e99613ad21274f269479bf4413fb294d697ef15ab897598afb931f56beb8e97af530aee20ce2bcb[email protected]:30303"),}
替換成:
with:
defaultBootNodes = []*discover.Node{
}
defaultTestNetBootNodes = []*discover.Node{
}
2- 生成預挖的公鑰和私鑰對:create premine address keypair:
- 需要一個公鑰位址,來産生neochain的創始區塊,并且需要控制它的私鑰來後面花費公鑰上面的币。
- 第一步,通過一個随機數産生器,我們來産生32位的私鑰,最簡單的做法就是通過下面指令産生:openssl rand -hex 32
- 第二步,我們得到私鑰為: eb1b1d5ffc51b07a64e622413479bb87xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (隻展示出一部分)
- 第三步,我們需要通過私鑰來得到公鑰,我們建立一個新的檔案 name: priv.txt , 然後複制privatekey 到這個txt檔案
- 第四步,我們可以通過ethereum的用戶端來産生公鑰,使用一下指令: geth account import priv.txt (如果我們沒有ethereum用戶端,我們需要自己編譯gvch并且采用相同的指令行)
- 我們可以得到下面的位址: {861fddd8a92457efb9f016517db38eb7fe586a6f}
- 出于安全原因,删除了priv.txt
3- 建立創始區塊 create the genesis block string:
- 我們利用 script gengen.go 來建立創始區塊,在gengen.go 中可以編輯一個貨币系統的參數,包括币的總量,區塊獎勵,區塊時間,區塊難度資訊,等等。
- 根據私鍊開發的需要,我們可以修改gengen.go 中的各種區塊鍊的參數。
- 第一 修改區塊鍊alive的時間戳
第80行,修改時間unix時間戳,用16進制。
(line 80): newGenesis.Timestamp="0x569CBF7F"
- 第二 我們把premine的位址替換成我們的位址
第90行(line 90): newGenesis.Coinbase="0x861fddd8a92457efb9f016517db38eb7fe586a6f"
- 第三 我們修改premine的數量
第92行 (line 92): premine:=[]byte('{"0x861fddd8a92457efb9f016517db38eb7fe586a6f":{"balance": "10000000000000000000000000"}}')
(格式為:premine address 和premine amount +18個0)
- 第四 我們也可以修改nonce、初始難度、gas limit 等資訊
因為neochain, 沒有太多人參與,因為我們把難度設定成cpu可以挖礦。
- 第五 所有參數修改好後,我們就可以儲存,然後運作,得到創始區塊的資訊。 用以下指令來産生創始區塊: command: go run gengen.go
- 第六 我們把運作結果複制到: go-neochain\core\default_genesis.go line 30
const defaultGenesisBlock = "H4sIAAAJbogA/6yRTWrDMBCF76J1FpZl/Ti7xGnaRVsK7QVmpFEjkO1iK+ASfPeqNhQK7SKQWQgkzfvmPenCnvvOEtuyYip+lSjZhr2FlsYE7cfSIFXd7I/6mC9eYKAuPcB4+kN6fWXi3ZQGOECCBcg5IhmHFYlK59XYWmjLrRG6oAolOSHAoXCoaosONQhDnGSBHE3pIQPvYXwMbUgLT/GdyWeH4H2w55g+V9v8Z/xTmE43TNP0oUMY14c1invnnIG6rKQmj7UvuJJc5wCGUHuSRoHyWbeLsbdse7lGlbub3n2PyoDX1A/wnjfdOcYN20OE9X/5/3bnef4KAAD//0BefdIIAgAA"
第七 – 修改區塊獎勵
- 在go-neochain\core\fees.go line 23
replace:
var BlockReward *big.Int = big.NewInt(5e+18)
with:
var BlockReward *big.Int = big.NewInt(0.01e+18)
- 在neochain中,我們把區塊獎勵設定成0.01
第八 – 儲存所有修改後,可以編譯用戶端 (編譯用戶端的說明詳見:see ethereum docs)
第九- 把ethereum的hardnode和keys,替換成我們自己的hardnode和keys
go-neochain\vch\backend.go line 71
replace:替換
defaultBootNodes = []*discover.Node{
// VCH/DEV Go Bootnodes
//discover.MustParseNode("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303"), // IE
//discover.MustParseNode("enode://de471bccee3d042261d52e9bff31458daecc406142b401d4cd848f677479f73104b9fdeb090af9583d3391b7f10cb2ba9e26865dd5fca4fcdc0fb1e3b723c786@54.94.239.50:30303"), // BR
//discover.MustParseNode("enode://1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfe[email protected]:30303"), // SG
// VCH/DEV cpp-neochain (poc-9.vchdev.com)
//discover.MustParseNode("enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303"),
}
with:
defaultBootNodes = []*discover.Node{
// VCH/DEV Go Bootnodes
discover.MustParseNode("enode://11936c3b31f940391025bba951777d4eafeffbd8aa24bf371b5166b2da6d69e9844b4778a35f68c106af8583be5c4500e69bb3639c10a30eabb311a044ac5202@62.210.105.88:17575"), // FR
discover.MustParseNode("enode://e1c30651e549149eb2bd68b77d5ca2a0ea662cd6364b846f456b5c12bd29978f738f55679b25538665d8797d3177c7160a4[email protected]:17575"), // CN
}
第十- 最後再重新編譯用戶端,并釋出各種版本的用戶端。 網絡就可以alive,可以參考ethereum的挖礦說明,包括如何搭建礦池,讓礦工參與挖礦。