Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Getting started with ethereum-examples of common commands (including user creation, mining, trading, etc.)

Shulou Source: shulou.com Published: 2022-06-03 05:37:21 09月11日 Update

Sample user Management of ethereum Common commands

Open the console

$geth-- datadir=path/to/custom/data/folder attach-- datadir "~ / .ethereum" database and KeyStore data directory

Create an account. The parameter is password.

Enter the following command in the console:

Personal.newAccount ("Write here a good, randomly generated, passphrase!")

"0x0fec688d601909d28faf6fe18cf6230d08b698b6"

By default, the first created user is the primary user

View users:

Eth.accounts

["0x0fec688d601909d28faf6fe18cf6230d08b698b6"]

The ranking of accounts reflects the time they created. The key file is stored under DATADIR / keystore and can be transferred between clients by copying the files it contains. These files are encrypted with a password and should be backed up if they contain any number of Ethernet. Note, however, that if you transfer individual key files, the order of the accounts submitted may change and you may not be able to end the same account in the same location. Therefore, please note that as long as you do not copy the external key file to your key store, you can only rely on the account index.

Unlock an account

Personal.unlockAccount ("0xf9ab190a9c56fd0d945eac9659c0c9519b13c64e")

Or

Here is to unlock the first account.

User1=eth.accounts [0]

Personal.unlockAccount (user1)

Digging ore

Start digging.

Miner.start ()

Digging a block will reward 5 etheric coins, and the reward from mining will go to the miner's account, which is called coinbase. By default, coinbase is the first account in the local account:

View mining account users

Eth.coinbase

"0xf9ab190a9c56fd0d945eac9659c0c9519b13c64e"

Now coinbase is account 0. If you want to transfer mining reward to other accounts, you can set other accounts to coinbase through miner.setEtherbase ().

Set up mining users

Miner.setEtherbase (eth.accounts [1])

True

Eth.coinbase

"0xb89bf2a212484ef9f1bd09efcd57cf37dbb1e52f"

Stop digging

Miner.stop ()

True

Check whether mining has stopped. If the output of eth.mining is false, mining has stopped.

Eth.mining

False

Trade

Check the account balance

Eth.getBalance (eth.accounts [0])

The unit of return value of getBalance () is that wei,wei is the smallest unit of etheric currency, 1 etheric coin = 10 to the 18th wei. To see how many etheric coins there are, you can use web3.fromWei () to convert the return value into etheric coins:

Web3.fromWei (eth.getBalance (eth.accounts [0]), 'ether')

three hundred and forty

Unit conversion: Ether- > Wei

Web3.toWei (1)

Unit conversion: Wei-> Ether

Web3.fromWei (10000000000000000)

Transfer

You need to unlock your account before transferring money, just like entering your bank card number and password

Eth.sendTransaction ({"from": "0x67128734480a0741595538d9d726f33addf83978", "to": "0x29a9a6bcf1ce7101ab93a029e2692298fc15e076", "gas": 31000, "gasPrice": web3.toWei (300), "value": "1"})

"0x54325698db1fbc85799b2f72070cddc457932abf0eef0d30d4fb2710ddafa941"

Eth.sendTransaction ({"from": "0x67128734480a0741595538d9d726f33addf83978", "to": "0x29a9a6bcf1ce7101ab93a029e2692298fc15e076", "value": "10000000000000000000000000000"})

"0x533d3c770aed09ede826c92e7460fd38d78a101752a7b3b25e4470d8594e77bb"

View the current total number of blocks:

Eth.blockNumber

sixty-nine

View the packaged transaction information in the block through the block number

Eth.getBlock (6)

{

Difficulty: 2

ExtraData: "0xd783010803846765746887676f312e392e32856c696e75780000000000000000cff7302b0c5515614e52f1584ff3f6aceb10dfa6e2facb347bfe3c023878d3857fa48774a98c721bcc1fb2419a177d577a0926e9f51d037095ba53257f7f307701"

GasLimit: 6246618

GasUsed: 21000

Hash: "0x5e2506ce385e38bbe23765a24ec25f9742e4a3a5af7cd071088081535a6a0dd2"

LogsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"

Miner: "0x0000000000000000000000000000000000000000"

MixHash: "0x0000000000000000000000000000000000000000000000000000000000000000"

Nonce: "0x0000000000000000"

Number: 6

ParentHash: "0x716da23fef7103042762025aabc83f7075fca516ab9dc6d436daa58b8350953b"

ReceiptsRoot: "0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2"

Sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"

Size: 713

StateRoot: "0x7c93a037c0750ddca8330d9c84912c622cd355c6978fc4267ffe2c8517a32469"

Timestamp: 1520398599

TotalDifficulty: 13

Transactions: ["0x54325698db1fbc85799b2f72070cddc457932abf0eef0d30d4fb2710ddafa941"]

TransactionsRoot: "0x712b5bba767dd0ecaeebbbeefdf097647a0f219f11f16e4a8a3d768b59ae442e"

Uncles: []

}

View the deal through the deal hash

Eth.getTransaction ("0x54325698db1fbc85799b2f72070cddc457932abf0eef0d30d4fb2710ddafa941")

{

BlockHash: "0x5e2506ce385e38bbe23765a24ec25f9742e4a3a5af7cd071088081535a6a0dd2"

BlockNumber: 6

From: "0x67128734480a0741595538d9d726f33addf83978"

Gas: 31000

GasPrice: 300000000000

Hash: "0x54325698db1fbc85799b2f72070cddc457932abf0eef0d30d4fb2710ddafa941"

Input: "0x"

Nonce: 5

R: "0xe14faca3d11a47ec4617927c84a04936dbaf783cc2187794e04299ce04352404"

S: "0x6da16b4e07a4fc721273d3b09da1c8b29ad4ce8022a99eb3f8317247cf7f5386"

To: "0x29a9a6bcf1ce7101ab93a029e2692298fc15e076"

TransactionIndex: 0

V: "0xa95"

Value: 1

}

View deal status

Txpool.status

{

Pending: 0

Queued: 0

}

Tags: Account user Ethernet transaction key file block unit account password reward command console data account number transfer storage control transfer input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Information NVidia vpn Shulou Tech Info