码迷,mamicode.com
首页 > 其他好文 > 详细

ethereum入门-常用命令示例(包括创建用户、挖矿、交易等)

时间:2018-03-07 15:21:08      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:ethereum命令

ethereum常用命令示例

用户管理

  • 打开控制台

     $ geth  --datadir=path/to/custom/data/folder attach
      --datadir“~/.ethereum”数据库和密钥库的数据目录
  • 创建账户,参数是密码
    在控制台输入下面命令:

    > personal.newAccount("Write here a good, randomly generated, passphrase!")
    "0x0fec688d601909d28faf6fe18cf6230d08b698b6"
    >
    默认第一个创建的用户为主用户

  • 查看用户:

    > eth.accounts
    ["0x0fec688d601909d28faf6fe18cf6230d08b698b6"]
    >
    账户的排序反映了他们创建的时间。 密钥文件存储在DATADIR / keystore下,可以通过复制其中包含的文件在客户端之间传输。 这些文件使用密码加密,如果它们包含任何数量的以太网,则应备份。 但是,请注意,如果您传输个别密钥文件,则提交的帐户顺序可能会发生变化,您可能无法在同一位置结束同一帐户。 因此请注意,只要您不将外部密钥文件复制到您的密钥存储区,只依赖帐户索引即可。

  • 解锁帐户

    > personal.unlockAccount("0xf9ab190a9c56fd0d945eac9659c0c9519b13c64e")
    或者
    这里是给第一个账户解锁
    >user1=eth.accounts[0]
    >personal.unlockAccount(user1)

挖矿

  • 开始挖矿

    > miner.start()
    挖到一个区块会奖励5个以太币,挖矿所得的奖励会进入矿工的账户,这个账户叫做coinbase,默认情况下coinbase是本地账户中的第一个账户:

  • 查看挖矿进账用户

    > eth.coinbase
    "0xf9ab190a9c56fd0d945eac9659c0c9519b13c64e"
    现在的coinbase是账户0,要想使挖矿奖励进入其他账户,通过miner.setEtherbase()将其他账户设置成coinbase即可

  • 设置挖矿用户

    > miner.setEtherbase(eth.accounts[1])
    true
    > eth.coinbase
    "0xb89bf2a212484ef9f1bd09efcd57cf37dbb1e52f"

  • 停止挖矿

    > miner.stop()
    true

  • 检查挖矿是否已经停止,eth.mining 输出为false时表示挖矿已经停止

    > eth.mining
    false

交易

  • 查看帐号余额

    > eth.getBalance(eth.accounts[0])

    getBalance()返回值的单位是wei,wei是以太币的最小单位,1个以太币=10的18次方个wei。要查看有多少个以太币,可以用web3.fromWei()将返回值换算成以太币:

    > web3.fromWei(eth.getBalance(eth.accounts[0]),‘ether‘)
    340
    单位转换: Ether–> Wei
    > web3.toWei(1)

    单位转换: Wei –> Ether

    > web3.fromWei(10000000000000000)

  • 转账
    转账前需要解锁帐号,就像输入银行卡号密码

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

    "0x54325698db1fbc85799b2f72070cddc457932abf0eef0d30d4fb2710ddafa941"

    > eth.sendTransaction({"from":"0x67128734480a0741595538d9d726f33addf83978", "to":"0x29a9a6bcf1ce7101ab93a029e2692298fc15e076", "value":"10000000000000000000000"})
    "0x533d3c770aed09ede826c92e7460fd38d78a101752a7b3b25e4470d8594e77bb"

  • 查看当前区块总数:

    > eth.blockNumber
    69

  • 通过区块号查看区块里打包的交易信息

    > 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: []
    }

  • 通过交易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
    }
    >

  • 查看交易状态

    > txpool.status
    {
    pending: 0,
    queued: 0
    }

ethereum入门-常用命令示例(包括创建用户、挖矿、交易等)

标签:ethereum命令

原文地址:http://blog.51cto.com/12880687/2083802

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!