密码学应用和加密货币实践

Ether

传输数据加密初探

  • PPP协议的pap验证:明文传输验证的用户名和密码

image-20200329153012935

  • PPP协议的chap验证:密文传输密码

image-20200329152934684

实践:发行虚拟货币

以太坊工具:https://ethfans.org/wikis/Ethereum-Geth-Mirror

运行环境:macOS 10.15.4 / geth 1.8.3

  1. 进入终端,新建挖矿目录mkdir mine,将下载的可执行文件geth放到这个目录下,进入该目录,

  2. 新建挖矿数据的目录并初始化

    1
    2
    3
    mkdir mycoin
    vim test.json
    geth --datadir="mycoin" init "test.json"

    test.json示例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    {
    "config": {
    "chainId":666,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0
    },
    "alloc" : {},
    "difficulty" : "0x400",
    "extraData" : "",
    "gasLimit" : "0x7A1200",
    "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp" : "0x00"
    }
  3. 进入后台

    1
    geth --networkid "30" --nodiscover --datadir="mycoin" console 2>> "mycoin"/"err.log"
  4. 查看指定区块

    1
    eth.getBlock(0)

    Screenshot2020-03-29 16.38.27

  5. 创建账户并查看

    1
    2
    3
    personal.newAccount("pay")     # 括号里是密码
    personal.newAccount("collect")
    eth.accounts
  6. 模拟挖矿

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # 设置挖矿地址,缺省则为第一个
    eth.coinbase
    # 查看账户余额
    eth.getBalance(eth.accounts[0])
    # 开始挖矿
    miner.start()
    # 结束挖矿:
    miner.stop()
    # 查看挖矿状态:
    miner.getHashrate()

    acounts[1]中余额增加

    miner.start()返回null:

    • geth-1.7.3以上版本的节点,在dev环境下执行miner.start()时,返回null。但其实miner已经执行。使用eth.blockNumber可查看到区块高度在增加

    miner.getHashrate返回0:

    • macOS上执行

      1
      2
      3
      4
      5
      wget http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.29_mac.pkg
      sudo installer -pkg ~/Desktop/cuda_7.0.29_mac.pkg -target /
      brew update
      brew tap ethereum/ethereum
      brew reinstall cpp-ethereum --with-gpu-mining --devel --headless --build-from-source
    • 执行命令查看挖矿状态

      1
      aticonfig --adapter=0 --od-gettemperature
  7. 转账

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 解锁账户
    personal.unlockAccount(eth.accounts[0], "pay")
    personal.unlockAccount(eth.accounts[1], "collect")
    # 转账
    eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(1, "ether")})
    # 查看交易
    eth.pendingTransactions
    # 继续挖矿,进而完成交易
    miner.start()

    accounts[1]中增加1个单位

title:密码学应用和加密货币实践

author:Anne416wu

link:https://www.annewqx.top/posts/4542/

publish time:2020-03-29

update time:2022-07-20


评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×