以太坊教程2-私有链基本操作

在上一篇文章中搭建好了私有链之后,开始进行一些 简单的操作。

终端运行:

@>>  geth  --datadir "./chain" --nodiscover console 2>>eth_output.log

启动geth

//给自己的两个账户重命名。
> user1 = eth.accounts[0]
"0xfd5db5967bb4600840adde5035b8de4d56176ad5"
> user2 = eth.accounts[1]
"0xa740690de331a76519133175c3f28aeb865de658"
 
//查看用户1的ETH
> eth.getBalance(user1)
5.93e+21
> eth.getBalance(user2)
0
 
//解锁,转账之前必须解锁操作。
> personal.unlockAccount("0xfd5db5967bb4600840adde5035b8de4d56176ad5","123456")
true
 
//将用户1给用户2转3个ETH
> eth.sendTransaction({from: user1, to: user2, value: web3.toWei(3, "ether")})
"0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee"
 
//然后查看用户2的名下还是0个ETH
> eth.getBalance(user2)
0
 
//打开挖矿
> miner.start()
null
 
//在转一次帐
> eth.sendTransaction({from: user1, to: user2, value: web3.toWei(3, "ether")})
"0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee"
 
//查看用户2的余额 ,发现有6个ETH了。
> eth.getBalance(user2)
6000000000000000000
 
 
//从日志查看交易在1188号区块。
INFO [07-16|17:41:03.037] 
//从日志查看交易在1188号区块。
INFO [07-16|17:44:51.391] Submitted transaction                    fullhash=0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee recipient=0xA740690De331A76519133175c3f28aEb865De658
INFO [07-16|17:45:36.188] Updated mining threads                   threads=0
INFO [07-16|17:45:36.188] Transaction pool price threshold updated price=18000000000
INFO [07-16|17:45:36.188] Starting mining operation 
INFO [07-16|17:45:36.189] Commit new mining work                   number=1188 txs=1 uncles=0 elapsed=459.147µs
INFO [07-16|17:45:59.028] Updated mining threads                   threads=0
INFO [07-16|17:46:02.920] Submitted transaction                    fullhash=0x976a0427817481a9a9f0c692e71151b3837ba6f3f9c4ce931df4d88d48f93b36 recipient=0xA740690De331A76519133175c3f28aEb865De658
INFO [07-16|17:47:22.389] Updated mining threads                   threads=0
INFO [07-16|17:47:22.389] Transaction pool price threshold updated price=18000000000
INFO [07-16|17:47:22.389] Starting mining operation 
INFO [07-16|17:47:22.390] Commit new mining work                   number=1188 txs=2 uncles=0 elapsed=697.907µs
INFO [07-16|17:47:38.532] Successfully sealed new block            number=1188 hash=83d471…e909e0
INFO [07-16|17:47:38.731] Commit new mining work                   number=1189 txs=0 uncles=0 elapsed=1.320ms
INFO [07-16|17:47:38.739] 
//查看区块结构
> eth.getBlock(1188)
{
  difficulty: 192530,
  extraData: "0xd68301080c846765746886676f312e3130856c696e7578",
  gasLimit: 4712388,
  gasUsed: 42000,
  hash: "0x83d47151ad9f1368954780a342118f6e392c81f1b06c5cf2bc02893f46e909e0",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  miner: "0xfd5db5967bb4600840adde5035b8de4d56176ad5",
  mixHash: "0xf6b8495978cb363dac64c2d81b7a34e1f470428ccc01d0dce3f31250e60b92bb",
  nonce: "0x7cd563b32336f4cb",
  number: 1188,
  parentHash: "0xbd8f131597c2b7d2aaba79d41cb86ac49bbaa127a457983e54542a680500de85",
  receiptsRoot: "0x7630e5ee1973f3546582909785a1ee5d9bf862187e1df48cfc6fe64bd634a0fe",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 761,
  stateRoot: "0x44880a00af0e7147e651a01c0a1c3d9f07b25c276b564c1e2dad61599b0eb374",
  timestamp: 1531734442,
  totalDifficulty: 199934928,
  transactions: ["0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee", "0x976a0427817481a9a9f0c692e71151b3837ba6f3f9c4ce931df4d88d48f93b36"],
  transactionsRoot: "0x8f225fd18cfa1aefc423adc7adb985a8c5f8782378e09737b993698021caef6d",
  uncles: []
}
//查看交易记录
> eth.getTransaction("0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee")
 
{
  blockHash: "0x83d47151ad9f1368954780a342118f6e392c81f1b06c5cf2bc02893f46e909e0",
  blockNumber: 1188,
  from: "0xfd5db5967bb4600840adde5035b8de4d56176ad5",
  gas: 90000,
  gasPrice: 18000000000,
  hash: "0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee",
  input: "0x",
  nonce: 0,
  r: "0x37c724075bd5c79c629f5ef09209ed1e9b01c4cc5410249c52b6dd7d33f33894",
  s: "0x47497db5fec98dfec5b0a9e04a6f8a74d26b6f92d3163010ec1d07e5b640a818",
  to: "0xa740690de331a76519133175c3f28aeb865de658",
  transactionIndex: 0,
  v: "0x2a",
  value: 3000000000000000000
}

猜你喜欢

转载自blog.csdn.net/u011164819/article/details/81557368