区块链技术探索

以太坊出块

2018-09-03  本文已影响20人  hasika

以太坊计划过度到pos共识机制,这使得挖矿变得过时。

  1. 开启挖矿

    //--mine开启挖矿,不带这个参数,启动的节点不会挖矿
    //--minnerthreads 挖矿的线程数,默认是CPU核心数
    geth --mine --minerthreads=1 
    
  2. 可以在console中开启或者停止挖矿

    >miner.start(8) //开启8个线程挖矿
    true
    >miner.stop() //停止挖矿
    true
    
  3. 设置挖矿收益账号

    geth --etherbase 1 --mine //设置第二个账号为挖矿收益账号
    geth --etherbase '0x32a6d3706ac2f88c86058cf204f325fe0660038d' --mine //设置账号地址为挖矿收益账号
    
  4. 设置挖矿收益账号(console)

    miner.setEtherbase(eth.accounts[2])
    
  5. 设置额外信息

    miner.setExtra("liangbin extra")
    
  6. 获取计算hash速度 H/s(Hash operations per second)

    >miner.hashrate
    
  7. 获取挖矿收益值

    > eth.getBalance(eth.coinbase).toNumber();
    70000000000000000000
    
  8. 解锁账号,否则不能花费以太

    > personal.unlockAccount(eth.coinbase)
    Unlock account 0x8cc4c2455b2d06b535606becc2f95e6a8b3ca258
    Passphrase: 
    true
    
  9. 查看哪些区块是我挖出的

    1. 定义js方法并保存在/home/lb/go-ethereum1.8.4/jsdir/minedBlocks.js

      function minedBlocks(lastn, addr) {
        addrs = [];
        if (!addr) {
          addr = eth.coinbase
        }
        limit = eth.blockNumber - lastn
        for (i = eth.blockNumber; i >= limit; i--) {
          if (eth.getBlock(i).miner == addr) {
            addrs.push(i)
          }
        }
        return addrs
      }
      // scans the last 1000 blocks and returns the blocknumbers of blocks mined by your coinbase 
      // (more precisely blocks the mining reward for which is sent to your coinbase).   
      minedBlocks(1000, eth.coinbase);
      //[352708, 352655, 352559]
      
      1. 进入console环境并加载js文件

        geth console
        > loadScript("/home/lb/go-ethereum1.8.4/jsdir/minedBlocks.js")
        true
        
      2. 调用方法

        > minedBlocks(20, eth.coinbase);
        [2318, 2317, 2316, 2315, 2314, 2313, 2312]
        

欢迎加入我的星球

我正在「哈斯卡和他的朋友们」和朋友们讨论有趣的话题,你一起来吧


我的星球.jpg
上一篇下一篇

猜你喜欢

热点阅读