初始化以太坊节点
geth -datadir /data/eth/ init /usr/local/eth/genesis.json
genesis.json:
{
"config": {
"chainId": 1000,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000061",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000",
"difficulty": "0x100",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {}
}
1 | chainId: 以太坊主网chainId为0,私链自己修改为一个任意Id。 |
启动私链的以太坊节点
geth -datadir /data/eth/ --networkid 1000 console
以太坊节点的主要操作:
admin
eth
personal
miner
> personal.listAccounts
[]
> personal.newAccount("qianrushi.org")
"0xcce01f2d1e7ab5ba8d9e5f68cf81b49d145e97fe"
> personal.listAccounts
["0xcce01f2d1e7ab5ba8d9e5f68cf81b49d145e97fe"]
> personal.newAccount("embeded.org")
"0x27643bec775e242fbc06c0457f781d62249f012c"
> personal.listAccounts
["0xcce01f2d1e7ab5ba8d9e5f68cf81b49d145e97fe", "0x27643bec775e242fbc06c0457f781d62249f012c"]
> personal.unlockAccount("0xcce01f2d1e7ab5ba8d9e5f68cf81b49d145e97fe")
Unlock account 0xcce01f2d1e7ab5ba8d9e5f68cf81b49d145e97fe
Passphrase:
true
当前区块信息
> eth.blockNumber
> eth.getBlock( eth.blockNumber )
账户余额
> web3.fromWei(eth.getBalance(eth.accounts[0]))