Install:
Remove node:
geth removedb --datadir node1
geth removedb --datadir node2
geth removedb --datadir node3
Create genesis.json:
{
"config": {
"chainId": 6666,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"ethash": {}
},
"nonce": "0x0",
"timestamp": "0x5ddf8f3e",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0xffffffff",
"difficulty": "0x0200",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": { },
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
Genesis configuration parameter description:
- nonce: 64-bit random number, used for mining
- timestamp: the timestamp of the genesis block
- parentHash: The value of the previous block
hash
, because it is a genesis block, so this value is 0- mixHash:
nonce
used for mining in conjunction with, generated by part of the previous blockhash
- extraData: Additional information, fill in arbitrarily
- gasLimit:
GAS
The total consumption limit of the pair, which is used to limit the sum of the transaction information that the block can contain- difficulty: difficulty value, the bigger the more difficult
- coinbase: the miner's account. After the first block is mined, the miner's account will be rewarded with ether.
- alloc: The default account and the amount of ether in the account, the test chain is easier to mine and can not be configured
- chainId: An independent blockchain network ID is specified, and nodes of different ID networks cannot be connected to each other
Initialize the node:
geth --datadir node1 init genesis.json
geth --datadir node2 init genesis.json
If an error is reported when initializing the genesis block:
Failed to write genesis block: unsupported fork ordering: eip150Block not enabled, but eip155Block enabled at 0
The original genesis block needs to be removed first
geth removedb --datadir node1
Reinitialize the genesis block
Start the node:
geth --datadir "node1" --networkid 6666 --port 10010 --http --http.api "eth,net,web3,miner,admin" --http.addr "localhost" --http.port 8546 console 2>node1.log
geth --datadir "node2" --networkid 6666 --port 10011 --http --http.api "eth,net,web3,miner,admin" --http.addr "localhost" --http.port 8547 console 2>node2.log
View the information of your own node:
admin.nodeInfo
Add node:
admin.addPeer('enode://535bb7b99b8dacd1011484ff3007c77809946b5869e8ab2e30c616bf8eb012d60eecc71e58ebcfbb7c0265b82a4f342e6a107a6b51f6f0ed2d1084c57aba55ae@[::]:10011')
View the node list:
admin.peers
Check account:
Read the account address information in the local keystore directory
eth.accounts
#或
personal.listAccounts
create Account:
The input parameter is the password, and the account address is stored in the keystore directory.
personal.newAccount()
#或
personal.newAccount(password)
Import account by private key:
The first parameter is the private key with 0x removed, and the second parameter is the password
personal.importRawKey("a290e50c1cde5128229cf9e286593c443084646e65e97c1bcd8afdaddea78fa7","111")
Unlock account:
personal.unlockAccount(account)
An error is reported when personal.unlockAccount() is executed:
geth新版本error:account unlock with HTTP access is forbidden at web3.js……
Reason for exception: In the new version of geth, for security reasons, the HTTP channel unlocking account is disabled by default
Solution: start node command add --allow-insecure-unlock
Check balances:
The balance is displayed in the smallest unit by default: 1 ETH=10 to the 18th power of wei
eth.getBalance(account1)
# ETH
web3.fromWei(eth.getBalance(account),'ether')
Current block:
eth.blockNumber
Start digging:
miner.start()
# x是启动几个核心
miner.start(x)
# 成功挖到一次后就停止
miner.start(1);admin.sleepBlocks(1);miner.stop()
End digging:
miner.stop()
Set up a mining account:
miner.setEtherbase(account)
transfer:
Before transferring money, you need to execute personal.unlockAccount() to unlock the account
The transfer will be successful only after miner.start() is executed
eth.sendTransaction({from:account1,to:account2,value:web3.toWei(5,'ether')})