第一步 安裝geth
下載地址:https://ethereum.github.io/go-ethereum/downloads/
點(diǎn)擊安裝勾選development tools

第二步 創(chuàng)建您的帳戶
在當(dāng)前文件夾下創(chuàng)建node1文件夾
創(chuàng)建一個(gè)賬戶(也稱為錢包)
Devnet $ geth --datadir node1/ account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 輸入你的密碼
Repeat passphrase: 確認(rèn)你的密碼
Address: {08a58f09194e403d02a1928a7bf78646cfc260b0}
第三步 geth命令創(chuàng)建您的Genesis文件
生成的文件是用于初始化區(qū)塊鏈的文件。第一個(gè)塊叫做創(chuàng)世塊,是根據(jù)genesis.json文件中的參數(shù)生成的。
Geth安裝后目錄下有很多可執(zhí)行文件如puppeth或bootnode。你可以在Geth github上找到完整的列表。
Puppeth可以創(chuàng)建創(chuàng)世區(qū)塊的json文件。
開始使用Puppeth:
1、win鍵 + r 進(jìn)入cmd命令行,進(jìn)入到安裝geth的文件夾執(zhí)行 puppeth 然后順序執(zhí)行下面操作
2、Please specify a network name to administer (no spaces, please)
> devnet
(這里隨便填寫一個(gè)網(wǎng)絡(luò)管理名稱即可,如有需要后面可以通過--network重新設(shè)置)
What would you like to do? (default = stats)
1. Show network stats
2. Configure new genesis
3. Track new remote server
4. Deploy network components
> 2
(這里選擇2,回車,配置新的創(chuàng)世區(qū)塊)
3、Which consensus engine to use? (default = clique)
1. Ethash - proof-of-work
2. Clique - proof-of-authorit
> 1
(這里選擇pow共識(shí)機(jī)制)
4、Which accounts should be pre-funded? (advisable at least one)
> 0x1234567890123456789012345678901234567890
(這個(gè)是設(shè)置預(yù)分配以太坊的賬戶,建議設(shè)置一個(gè)有私鑰的地址可以后面測(cè)試使用,設(shè)置好后再按一次回車)
5、Specify your chain/network ID if you want an explicit one (default = random)
> 666
(這里就是鏈的chainId,可以隨意輸入也可以不輸直接回車默認(rèn)隨機(jī)數(shù)字)
6、What would you like to do? (default = stats)
- Show network stats
- Manage existing genesis
- Track new remote server
- Deploy network components
> 2
(管理已擁有的創(chuàng)世塊)
7、 1. Modify existing fork rules
2. Export genesis configuration
3. Remove genesis configuration
> 2
(選擇導(dǎo)出創(chuàng)世配置)
8、Which file to save the genesis into? (default = devnet.json)
> ./genesis.json
(導(dǎo)出的路徑及文件名)
OK,到這里創(chuàng)世json文件創(chuàng)建完成了
第四步 geth命令初始化節(jié)點(diǎn)
現(xiàn)在我們有了這個(gè)genesis.json文件,可以初始化創(chuàng)世塊了!
進(jìn)入到geth安裝文件夾下執(zhí)行
geth --datadir node1/ init genesis.json
第五步 bootnode命令操作
bootnode唯一的目的是幫助節(jié)點(diǎn)發(fā)現(xiàn)彼此(記住,以太坊區(qū)塊鏈?zhǔn)且粋€(gè)對(duì)等網(wǎng)絡(luò))
初始化 bootnode
bootnode -genkey boot.Key
啟動(dòng)bootnode服務(wù)
bootnode -nodekey boot.key -addr:30310
隨意使用任何您喜歡的端口,但請(qǐng)避免使用主流端口(例如HTTP)。30303用于公共以太坊網(wǎng)絡(luò)。
第六步 geth命令啟動(dòng)節(jié)點(diǎn)
geth --datadir .\node1\ --syncmode 'full' --port 30311 --rpc --rpcaddr '127.0.0.1' --rpcport 8501 --rpcapi 'personal,db,eth,net,web3,txpool,miner' --bootnodes 'enode://ca88962dbcc8eb0c7587789866f21db68cdf32ad1ea890fe0d9f8fe010f7e9afe2e6a88d5c9d418be61a10b8a31b1e7c55213bb426dab91596ae36bd7d559333@127.0.0.1:30310' --networkid 666
參數(shù)解釋:
--syncmode 'full' 有助于防止錯(cuò)誤丟棄錯(cuò)誤的傳播塊。
--port 是node1的端口
--rpcapi 允許RPC調(diào)用的模塊
--bootnodes 要連接的bootnode
--networkId genesis.json文件中的chainId
第七步 與您的節(jié)點(diǎn)進(jìn)行交互
通過RPC方式
$ cd devnet
devnet$ geth attach 'http://localhost:8501'
Welcome to the Geth JavaScript console!
instance: Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9
coinbase: 0x87366ef81db496edd0ea2055ca605e8686eec1e6
at block: 945 (Sat, 10 Feb 2018 21:16:14 CET)
modules: eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
使用Geth控制臺(tái)
>net.version
"1515"
> eth.blockNumber
1910
> eth.coinbase
"0x87366ef81db496edd0ea2055ca605e8686eec1e6"
> eth.sendTransaction({'from':eth.coinbase, 'to':'0x08a58f09194e403d02a1928a7bf78646cfc260b0', 'value':web3.toWei(3, 'ether')})
"0x299a99baa1b39bdee5f02e3c660e19e744f81c2e886b5fc24aa83f92fe100d3f"
>eth.getTransactionReceipt("0x299a99baa1b39bdee5f02e3c660e19e744f81c2e886b5fc24aa83f92fe100d3f")
{
blockHash: "0x212fb593980bd42fcaf3f6d1e6db2dd86d3764df8cac2d90408f481ae7830de8",
blockNumber: 2079,
contractAddress: null,
cumulativeGasUsed: 21000,
from: "0x87366ef81db496edd0ea2055ca605e8686eec1e6",
gasUsed: 21000,
logs: [],
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
status: "0x1",
to: "0x08a58f09194e403d02a1928a7bf78646cfc260b0",
transactionHash: "0x299a99baa1b39bdee5f02e3c660e19e744f81c2e886b5fc24aa83f92fe100d3f",
transactionIndex: 0
}
> exit
(退出)
來自:https://www.haowenbo.com/articles/2019/07/24/1563963176492.html