- 掌握区块链基本原理
- 掌握私有链的搭建
需要提前安装好Ubuntu 虚拟机
安装geth
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install Ethereum
输入geth -v,检测安装是否成功
创建创始域文件
cd Desktop
cd ethereum
vi genesis.json
{
"config": {
"chainId": 666,
"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": "0x47b760",
"difficulty": "0x00002",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": { },
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
退出并保存
创建创世区块
geth --data init genesis.json
建立geth
启动私有链
输入
"enode://30f569143293d927d82269d0371f85c076d7bef659fbb955266b800ceb23ff8581141597b916d3fee3bc726b7ea7f4756933b2a0b7cd2e0656d0a3d706c15308@127.0.0.1:3000"geth --port 3001 --networkid 666 --datadir="data" --maxpeers=3 --http --http.port 8546 --http.addr 127.0.0.1 --http.corsdomain "*" --
创建账户
personal.newAccount("123")
弹出账户地址
此步骤弹出的账户地址需要自行记录
链接目标节点
输入admin.nodeInfo.enode
得到
"enode://30f569143293d927d82269d0371f85c076d7bef659fbb955266b800ceb23ff8581141597b916d3fee3bc726b7ea7f4756933b2a0b7cd2e0656d0a3d706c15308@127.0.0.1:3000"
打开新的终端输入apa,找到自己的IP地址,输入admin.addPeer
("enode://30f569143293d927d82269d0371f85c076d7bef659fbb955266b800ceb23ff8581141597b916d3fee3bc726b7ea7f4756933b2a0b7cd2e0656d0a3d706c15308@IP地址:3000")
以下是开始以后可以进行的操作
开始挖矿
miner.star(1);
终止挖矿
miner.stop()
查询余额
eth.getBalance(eth.accounts[0])
解锁钱包
personal.unlockAccount(eth.accounts[0])
交易
amount=web3.toWeb(1,'ether')
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:amount})
开始
运行成功。