==============================
创建 Private Networks ============================== 1.准备 下载和安装命令行工具geth,; 创建CustomGenesis.json创世区块的配置{ "nonce": "0x0000000000000042", "timestamp": "0x0", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x0", "gasLimit": "0x8000000", "difficulty": "0x400", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x3333333333333333333333333333333333333333", "alloc": { }}
2.初始化
geth --identity "CSQNodeName" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir ~/.ethereum_private --port "30303" --nodiscover --rpcapi "db,eth,net,web3,personal" --networkid 1999 init /Volumes/disk2/software/blockchain/CustomGenesis.json
3.运行实例
geth --identity "CSQNodeName" --rpc --rpccorsdomain "*" --datadir ~/.ethereum_private --rpcapi "eth,net,web3,admin,personal" --shh --dev console#如果你想连接Ethereum的测试网络,可运行如下命令geth --testnet --rpc --rpcaddr "127.0.0.1" --rpcport "8545" --rpcapi "db,eth,net,web3" --rpccorsdomain "http://localhost:8000"4.创建帐号,密码是 123456 >personal.newAccount("123456") "0x60249051528212bd2fd0e72933b5931836065b56" 5.挖矿 set it as the etherbase: >miner.setEtherbase(personal.listAccounts[0]) >miner.start() Automatic pregeneration of ethash DAG ON (ethash dir: ~/.ethash)
#要花费10分钟左右时间,数据保存在~/.ethash目录下,约1G大小。
需要开户另外一个实例才可以结束miner :((Update:可以停止,不用管滚动的屏幕,直接复制miner.stop()粘贴,回车就可以停止挖矿)
>miner.stop()6.执行多个console
如果实例已经在运行,可以执行 geth attach 使用旧的实例(数据库不能同时服务两个实例)geth --identity "CSQNodeName" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir ~/.ethereum_private --port "30303" --nodiscover --rpcapi "db,eth,net,web3" --networkid 1999 --ipcpath ~/.ethereum_private/geth.ipc attach上面的命令在osx下会提示找不到geth.ipc文件的情况,即使指定了ipcpath也不行(可能是geth的bug),它只会去/Users/zhugan/Library/Ethereum/geth.ipc下找, 需要手工修正 ln -s ~/.ethereum_private/geth.ipc ~/.ethereum_private/geth.ipc
查询加载的rpc api模块(这涉及到后面使用wallet是否支持personal协议)
web3.rpc
更多指令参考
7.查询eth余额balance = web3.fromWei(eth.getBalance(eth.accounts[0]), "ether");
8.用Ethereum Wallet连上私有网络
open -a /Applications/Ethereum\ Wallet.app --args --rpc ~/.ethereum_private/geth.ipc --rpcapi "eth,web3,personal"
然后可以用Wallet也创建contracts了!(测试发现创建不了合约:The method personal_sendTransaction does not exist/is not available,事实上node有启用personal rpcapi,不知什么原因会提示找不到方法?)
获取钱包命令参数
/Applications/Ethereum\ Wallet.app/Contents/MacOS/Ethereum\ Wallet --help
9.参考
- geth命令参数
- Ethereum Wallet(Mist)命令参数
- web3指令参考