[Southwest University of Science and Technology Competition and Practice] Construction and Implementation of Private Chain

  1. Master the basic principles of blockchain
  2. Master the construction of private chain

You need to install the Ubuntu virtual machine in advance
to install 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
insert image description here

Enter geth -v to check whether the installation is successful
Successful installation

Create the founding domain file
insert image description here

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"
}

exit and save

Create a genesis block
geth --data init genesis.json
insert image description here

Create geth
to start the private chain
Enter
"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 "*" --
to create an account

personal.newAccount("123")

Pop-up account address
The account address that pops up in this step needs to be recorded by yourself

link target node

输入admin.nodeInfo.enode

get

"enode://30f569143293d927d82269d0371f85c076d7bef659fbb955266b800ceb23ff8581141597b916d3fee3bc726b7ea7f4756933b2a0b7cd2e0656d0a3d706c15308@127.0.0.1:3000"

Open a new terminal and enter apa, find your own IP address, and enter admin.addPeer

"enode://30f569143293d927d82269d0371f85c076d7bef659fbb955266b800ceb23ff8581141597b916d3fee3bc726b7ea7f4756933b2a0b7cd2e0656d0a3d706c15308@IP地址:3000"

Here's what you can do after you start

开始挖矿
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})

Start
insert image description here
running successfully.

Guess you like

Origin blog.csdn.net/gy0797/article/details/128100341