In the Ethereum system, state is made up of objects called "accounts" (each account consists of a 20-byte address) and state transitions that transfer value and information between two accounts. An Ethereum account consists of four parts: A random number that determines a counter that can only be processed once per transaction The current Ethereum balance of the account The account's contract code, if any Storage of the account (empty by default) Simply put, every Ethereum account consists of a pair of public and private keys. The public key can be understood as the account address, which can be accessed by any other account A private key can be understood as an encrypted password, and this pair of public and private keys together form a uniquely identified Ethereum account. For example, in the first Ethereum account eth.accounts[0] we established in the previous section, the address 0xbcf5b841303bc08026ce2d3b8f83498ffe42c12f is the public key, and the encrypted password is the private key. Increase accounts We can enter the command personal.newAccount("123") to create a new account, (note that 123 can be changed to any other password)
When the Ethereum private chain is mining, the mined ether will be deposited into the first Ethereum account, that is, eth.accounts[0], and eth.accounts[1] will not have ether by default. At this time, we can use the following command to check the Ethereum balance in eth.accounts[0].
How to convert Ethereum between two accounts As mentioned earlier, the public key (address) of each account is the core of all Ethereum account operations, but the address string is too long, so we use acc0/acc1 to represent accounts[0] and [1] respectively, and set 0.01 ETH to be transferred
At this time, we can use eth.sendTransaction to transfer 0.01 ETH from acc0 to acc1.
An Ethereum protection mechanism that automatically locks accounts every once in a while, at which point any conversion of ETH between accounts will be rejected unless the account is unlocked. At this time, we need to execute personal.unlockAccount(acc0) and enter the password to unlock acc0.
At this time, we re-execute the command eth.sendTransaction({from: acc0, to: acc1, value: amount}), and the result is as follows:
We can see that at this time, acc1 has a value of 100000000000000000000000, instead of the previous 0. But why is the value so big when we obviously want to give 0.01 ether coins? In fact, it is correct, we only need to enter the command web3.fromWei(1000000000000000000, "ether") to know.
The basic unit of Ether
The smallest unit of Ether coin is Wei, which is also the default unit of the command line, and then one unit for every 1000, in that order
kwei (1000 Wei) mwei (1000 KWei) gwei (1000 mwei) szabo (1000 gwei) finney (1000 szabo) ether (1000 finney) Simply put, it is 1 ETH = 100000000000000000000 Wei (this is why we transferred 0.01 ETH in the previous stoppage, but the result was very long) How to convert between ether and wei
|