两种以太坊客户端可以挑选:
Eth - C++ implementation
Geth - Go implementation
本教程是根据Geth. 装置教程可以到 frontier gitbook.
创立创世块
创世块的最大特点是第一个块,所以没有与之前的块产生联系。在比特币体系里,这个创世块是被写入源码,但对于以太坊而言,创世块可以是任何你喜爱的东西。你也可以把这个当成是体系的一个漏洞。可是共识算法保证其它人除非归入你的创世块,否则是不会有效的。(以后再详细说)
Great, so how do we make one of these genesis blocks? Well its fairly simple the following JSON is all you really need:
https://bicoin8.com/wp-content/uploads/2023/04/202304211cHpE0.jpg
"nonce": "0xdeadbeefdeadbeef",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0",
"gasLimit": "0x8000000",
"difficulty": "0x400",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": https://bicoin8.com/wp-content/uploads/2023/04/202304211cHpE0.jpg
}
}
Kudos to obscuren
在本地硬盘上存储这个 JSON,然后运行以下指令:
$ geth --genesis <genesis json file path> --datadir <some path to an empty folder> --networkid 123 --nodiscover --maxpeers 0 console
这个指令做了如下几个工作:
调用创世块JSON进区块链里。
运用 datadir 来存储相关数据,并且保护新创立的区块及其它数据 (declared to prevent you clobbering your main net data, wouldn’t want to overwrite all those blocks you spent time downloading!)
运用网络ID ‘1’ 保证我们无法与主网的节点进行通讯。 – “connections between nodes are valid only if peers have identical protocol version and network id”
禁用同伴发现。
把maxpeers 设置为 0禁用网络。
以控制台形式发动 geth客户端,这样你就可以与你的新区块链接/节点进行通讯。
接下来就可以根据 testing contracts and transactions 的指示创立区块和帐户了。我这儿的区别是禁用了PRC, 表现证明的公认搜集过程( the proof performance metric gathering processes) ,extra verbosity and vmdebu,目的是简单化。
在上述创世块里,我把难度设置的很低,这样的话我的本地电脑就可以挖矿,很容易获得以太币。
种子帐户 accounts with allocation
接下来,就有必要创立新的种子帐户了(以便存储挖矿所得的以太币)。 很简单,先创立一个新区块链和新帐户:
$ geth --genesis <genesis json file path> --datadir /.../dapps/test-genesis/.ethereum --networkid 123 --nodiscover --maxpeers 0 console
I0829 13:30:07.340636 3987 database.go:74] Alloted 16MB cache to /.../dapps/test-genesis/.ethereum/blockchain
I0829 13:30:07.342982 3987 database.go:74] Alloted 16MB cache to /.../dapps/test-genesis/.ethereum/state
I0829 13:30:07.345055 3987 database.go:74] Alloted 16MB cache to /.../dapps/test-genesis/.ethereum/extra
I0829 13:30:07.347363 3987 backend.go:291] Protocol Versions: [61 60], Network Id: 12345
I0829 13:30:07.347738 3987 backend.go:303] Successfully wrote genesis block. New genesis hash = 82b6159155c00fb0b420046012a02257a176ad5dcfce4be4a15da39c166518e2
I0829 13:30:07.347771 3987 backend.go:328] Blockchain DB Version: 3
I0829 13:30:07.347866 3987 chain_manager.go:241] Last block (#0) 82b6159155c00fb0b420046012a02257a176ad5dcfce4be4a15da39c166518e2 TD=1024
I0829 13:30:07.353373 3987 cmd.go:124] Starting Geth/v1.0.1/darwin/go1.4.2
I0829 13:30:07.353470 3987 server.go:312] Starting Server
I0829 13:30:07.353610 3987 backend.go:564] Server started
I0829 13:30:07.353548 3987 server.go:549] Listening on [::]:30310
I0829 13:30:07.353961 3987 ipc_unix.go:78] IPC service started (/.../dapps/test-genesis/.ethereum/geth.ipc)
instance: Geth/v1.0.1/darwin/go1.4.2
datadir: /.../dapps/test-genesis/.ethereum
coinbase: 0x1fb891f92eb557f4d688463d0d7c560552263b5a
at block: 0 (1970-01-01 01:00:00)
modules: admin:1.0 db:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 shh:1.0 txpool:1.0 web3:1.0
> personal.newAccount("mypassword");
'0x1fb891f92eb557f4d688463d0d7c560552263b5a'
上面代码的最终一行创立了一个新的帐户,其地址是 0x1fb891f92eb557f4d688463d0d7c560552263b5a.
创立帐户后,用 <ctrl-c> 退出geth客户端,然后在你的datadir文件夹里,保留 keystore/ 这个文件夹,其他的全部删掉。
$ cd <your datadir>
$ rm -rf `ls | grep -v keystore`
接下来就是见证奇观的时分,改写你的创世块JSON,把下面的代码加入 alloc 键:
"alloc": https://bicoin8.com/wp-content/uploads/2023/04/202304211cHpE0.jpg
"<your account address e.g. 0x1fb891f92eb557f4d688463d0d7c560552263b5a>": https://bicoin8.com/wp-content/uploads/2023/04/202304211cHpE0.jpg
"balance": "10000000000000000000"
}
}
现在从头运行geth指令行,运用方才改写过的 genesis json文件,还有相同的datadir,然后你会发现帐户余额里,多了10个以太币出来。
$ geth --genesis <updated genesis json file path> --datadir /.../dapps/test-genesis/.ethereum --networkid 123 --nodiscover --maxpeers 0 console
I0829 13:30:07.340636 3987 database.go:74] Alloted 16MB cache to /.../dapps/test-genesis/.ethereum/blockchain
I0829 13:30:07.342982 3987 database.go:74] Alloted 16MB cache to /.../dapps/test-genesis/.ethereum/state
I0829 13:30:07.345055 3987 database.go:74] Alloted 16MB cache to /.../dapps/test-genesis/.ethereum/extra
I0829 13:30:07.347363 3987 backend.go:291] Protocol Versions: [61 60], Network Id: 12345
I0829 13:30:07.347738 3987 backend.go:303] Successfully wrote genesis block. New genesis hash = 82b6159155c00fb0b420046012a02257a176ad5dcfce4be4a15da39c166518e2
I0829 13:30:07.347771 3987 backend.go:328] Blockchain DB Version: 3
I0829 13:30:07.347866 3987 chain_manager.go:241] Last block (#0) 82b6159155c00fb0b420046012a02257a176ad5dcfce4be4a15da39c166518e2 TD=1024
I0829 13:30:07.353373 3987 cmd.go:124] Starting Geth/v1.0.1/darwin/go1.4.2
I0829 13:30:07.353470 3987 server.go:312] Starting Server
I0829 13:30:07.353610 3987 backend.go:564] Server started
I0829 13:30:07.353548 3987 server.go:549] Listening on [::]:30310
I0829 13:30:07.353961 3987 ipc_unix.go:78] IPC service started (/.../dapps/test-genesis/.ethereum/geth.ipc)
instance: Geth/v1.0.1/darwin/go1.4.2
datadir: /.../dapps/test-genesis/.ethereum
coinbase: 0x1fb891f92eb557f4d688463d0d7c560552263b5a
at block: 0 (1970-01-01 01:00:00)
modules: admin:1.0 db:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 shh:1.0 txpool:1.0 web3:1.0
> primary = eth.accounts[0];
'0x1fb891f92eb557f4d688463d0d7c560552263b5a'
> balance = web3.fromWei(eth.getBalance(primary), "ether");
'10'
声明:本网站所提供的信息,均收集于互联网,只供参考之用。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。