(2), Ethereum mining and transfer experience

1. Start geth

geth --dev console 2>> geth_dev_log  

or:

geth --identity "TestNode" --rpc--rpcport "8545" --datadir /opt/data/ --port "30303"--nodiscover --dev --dev.period 1 console>> geth_dev_log

2. View the list of miner accounts, create a miner account, and mine

eth.accounts // View the list of miner accounts

personal.newAccount('132410') // password  

personal.newAccount('166200') // password  

eth.accounts  

user1 = eth.accounts[0]  //user1  

user2 = eth.accounts[1]  //user2  

miner.start (   ) //Excavation....wait 3 minutes ....

Stop mining and see the account income...

miner.stop() // stop mining  

eth.getBalance(user1) // View the income of the first miner  

eth.getBalance(user2) // View the income of the second miner  

 

3. Transfer

It seems that the first miner is a big tyrant, and the second miner is a pauper! This is because geth will allocate the mining income to the first account by default...

Below is the average wealth, transfer 100 million ETH to the second miner as a labor fee!

eth.sendTransaction({from: user1, to: user2, value: web3.toWei(100000000, 'ether')}) // transfer 100 million ether to the second miner  

If the result prompts failure, the reason is that user1 is not unlocked. Payment cannot be made without unlocking. The so-called unlocking process is actually to enter the account password once, which is equivalent to the concept of entering the account password before bank transfer.

After the unlocking is performed, the transfer is performed again,

After the transfer is successful, the transaction number is generated:

0x05362719cd12e38a61640de72e52a0f5fb4a188481738da21ff7a885c92d94fb

After that, check user2's account to see if the money has arrived?

personal.unlockAccount(user1, '123456') // Unlock user1  

eth.sendTransaction({from: user1, to: user2, value: web3.toWei(100000000, 'ether')})  

eth.getBalance (user2)  

eth.getBalance (user1) 

If the transfer has not been successful! It may be because the transaction confirmation of the blockchain is achieved through mining. No one is mining, which means that the block with transaction information (that is, the large string of strings just now) is not in each node of the network. Records, and lack of records means that no one approves the transaction... So although the current transaction is successful, the transaction still needs to wait for the confirmation of the whole network... Let's continue to start mining... Mining for 10 seconds , and then look at the results...

miner.start() // Start mining ...  

miner.stop() // Stop mining after 10 seconds  

eth.getBalance(user2) // Look at user2 's account again  

eth.getBalance(user1) // Look at the situation of user1 at the same time  


Sure enough it was successful... Now switch to the second SSH to see the log output

In the log, you can see the time when the transaction was generated and the beneficiaries, and at the same time, you can see the number of transaction information carried in the block after mining starts...

 OK, with this link, the mining process can basically be clarified.

 

In reality, the actual meaning of mining lies in applying for the right to bookkeeping. Once it helps to register the accounts for transactions on the network, it is equivalent to approving the transaction of the other party.

 

 The income of mining comes from the transaction commission in the ether. The commission for the bookkeeping right of each transaction is very small, but many transactions are often recorded in a block. value is also greater.



Ethereum basic commands
1. View the list of miner accounts:
eth.accounts
2. View cionbase
eth.coinbase
3. View the number of blocks
eth.blockNumber
4. Create a new miner account, password 132410
personal.newAccount('132410') 
5. Specify the mining process number
user1 = eth.accounts[0]
6. Mining miner.start
()
7. Stop
mining miner.stop()
8. Check the first miner's income
eth.getBalance(user1)
9. Transfer 5 to the second miner eth.sendTransaction
({from: user1, to: user2, value: web3.toWei(5, 'ether')})
10. Unlock user1
personal.unlockAccount(user1, '123456') 
11. Change another user mining
miner.setEtherbase("0x3e5b31e581546f2900c0f3289153c788c92a2b41")


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325896010&siteId=291194637