以太坊客户端常用命令

关于账户

> personal.newAccount('123456')  #创建新账户
"0x85d755f0ea9678ea20f5962a3657c32f65cbc70f"
> personal.listAccounts #查看账户列表
["0x85d755f0ea9678ea20f5962a3657c32f65cbc70f"]
> eth.getBalance('0x85d755f0ea9678ea20f5962a3657c32f65cbc70f') #查看账户有多少以太坊 
0 

关于挖矿

> miner.start() #停止挖矿
INFO [01-03|10:44:06] Updated mining threads                   threads=0
INFO [01-03|10:44:06] Transaction pool price threshold updated price=18000000000
INFO [01-03|10:44:06] Starting mining operation
null
> INFO [01-03|10:44:06] Commit new mining work                   number=35 txs=0 uncles=0 elapsed=238.341µs
INFO [01-03|10:44:08] Successfully sealed new block            number=35 hash=27e3d0…60d8cb
INFO [01-03|10:44:08] 🔨 mined potential block                  number=35 hash=27e3d0…60d8cb
INFO [01-03|10:44:08] Commit new mining work                   number=36 txs=0 uncles=0 elapsed=150.123µs
INFO [01-03|10:44:08] Successfully sealed new block            number=36 hash=0deebd…468a57
> miner.stop() #停止挖矿
true

查看区块数量

> eth.blockNumber
56

关于交易

#从0xbea06305593c53629fdf99220f49be9a674e26f3转账到0x1a1f2b98d45922b15e4c8d1f8b59b3a1c90e5537一共3个以太坊币
> eth.sendTransaction({from:"0xbea06305593c53629fdf99220f49be9a674e26f3",to:"0x1a1f2b98d45922b15e4c8d1f8b59b3a1c90e5537",value:web3.toWei(3,"ether")})
Error: authentication needed: password or unlock
    at web3.js:3143:20
    at web3.js:6347:15
    at web3.js:5081:36
    at <anonymous>:1:1

交易前需要预先解锁账户

> personal.unlockAccount(eth.accounts[0]) #解锁账户并输入密码
Unlock account 0xbea06305593c53629fdf99220f49be9a674e26f3
Passphrase:
true

再执行交易,返回一个交易地址0x836cebf1319f6bf448f930e8e197da49b4c0454591d070d55bd94eced748a123,通过eth.getTransaction()可以查找交易的数据

> eth.sendTransaction({from:"0xbea06305593c53629fdf99220f49be9a674e26f3",to:"0x1a1f2b98d45922b15e4c8d1f8b59b3a1c90e5537",value:web3.toWei(3,"ether")})
INFO [01-03|14:28:38] Submitted transaction                    fullhash=0x836cebf1319f6bf448f930e8e197da49b4c0454591d070d55bd94eced748a123 recipient=0x1a1f2B98d45922b15e4C8d1F8b59B3a1c90e5537
"0x836cebf1319f6bf448f930e8e197da49b4c0454591d070d55bd94eced748a123"

矿池有未打包交易

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

交易账户并没有完成转账需要再次执行挖矿,才能完成交易

> miner.start()

查看交易,这次交易被记录在区块73上

> eth.getTransaction("0x836cebf1319f6bf448f930e8e197da49b4c0454591d070d55bd94eced748a123")
{
  blockHash: "0x812c8e284921e871431939a76cc958d0be72eb8bf95d3855975d3e5e67db61ef",
  blockNumber: 73,
  from: "0xbea06305593c53629fdf99220f49be9a674e26f3",
  gas: 90000,
  gasPrice: 18000000000,
  hash: "0x836cebf1319f6bf448f930e8e197da49b4c0454591d070d55bd94eced748a123",
  input: "0x",
  nonce: 0,
  r: "0x2ea5a1a60f63b9badb39df143593607de8c18ffff02ec4f56b5cdcee86e0437c",
  s: "0x4697674f5b004f852107b3d9b9d805984550ca0059aeef6ce54d92c4f43842e0",
  to: "0x1a1f2b98d45922b15e4c8d1f8b59b3a1c90e5537",
  transactionIndex: 0,
  v: "0x6095",
  value: 3000000000000000000
}

查看交易所在的区块,里面有打包的交易

> eth.getBlock(73)

{
  difficulty: 131072,
  extraData: "0xd883010703846765746887676f312e392e328664617277696e",
  gasLimit: 3999302911,
  gasUsed: 21000,
  hash: "0x812c8e284921e871431939a76cc958d0be72eb8bf95d3855975d3e5e67db61ef",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  miner: "0xbea06305593c53629fdf99220f49be9a674e26f3",
  mixHash: "0xe436dac52c833114e78a06db5e146734a80bfbed7c1c4e08839866d4e68fc81c",
  nonce: "0x1ad4d2c242935543",
  number: 73,
  parentHash: "0xe9ed3937a37fd69e224f076e0b23e78447313842fc974b23a8b9c47caee457c3",
  receiptsRoot: "0x1534c258cd647b99d8236c4b4234900ed1651e261887ec94908300f0a0565b56",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 653,
  stateRoot: "0x806969c588754469c6fd5cc8b3bfb79a02973014eaedb5fbd9ecd1e607499fcb",
  timestamp: 1514961161,
  totalDifficulty: 9667121,
  transactions: ["0x836cebf1319f6bf448f930e8e197da49b4c0454591d070d55bd94eced748a123"],
  transactionsRoot: "0x61453ae21c735239c762de9a56c106acb2604cace68bf3437a2f5c456da6f7b8",
  uncles: []
}

以下为公有链的一些常用命令

检查连接和ENODE身份

要检查客户端在交互控制台上连接了多少对等端点,net模块有两个属性可以提供信息,告诉你对等端点的数量以及你是否在监听的节点。

> net.listening
true
> net.peerCount
4

了解更多关于连接对等端点的信息,比如IP地址、端口号和支持协议,用管理员对象的peers功能。admin.peers会返回到现在已连接的对等端点列表。

> admin.peers
[{
    caps: ["eth/63"],
    id: "133b8b907d2e6124071495fe39cd25367dddb91631ed908fa93b50e1777c913f28bcf54edb9546b782a6405b62d8dd7689c8cbbaf01f6f8c6ebdf6c7629a5369",
    name: "Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9",
    network: {
      localAddress: "10.60.204.121:51967",
      remoteAddress: "92.91.128.128:30303"
    },
    protocols: {
      eth: {
        difficulty: 17179869184,
        head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
        version: 63
      }
    }
}, {
    caps: ["eth/63"],
    id: "24e76dc7890b6f5155b3898b821e9f843276453c6da0fcf6667c602b7bcb56b57d04249c36b4ac63ce7e8842dcaf3633b1951f34a49979e44d707e132fcc5b64",
    name: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
    network: {
      localAddress: "10.60.204.121:52022",
      remoteAddress: "75.158.33.187:30303"
    },
    protocols: {
      eth: {
        difficulty: 17179869184,
        head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
        version: 63
      }
    }
}, {
    caps: ["eth/63"],
    id: "55819047ea299de226b83695f49d469298e312b2d13bbbf4184a69e7804eaee0374a7de15aeb48c5fc84ef77248e9ae7d1d7050c516991644966e28e1e0d8969",
    name: "Geth/v1.7.2-stable-1db4ecdc/windows-amd64/go1.9",
    network: {
      localAddress: "10.60.204.121:51963",
      remoteAddress: "79.35.105.24:30303"
    },
    protocols: {
      eth: {
        difficulty: 17179869184,
        head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
        version: 63
      }
    }
}, {
    caps: ["eth/62", "eth/63", "par/1", "par/2", "pip/1"],
    id: "f6353b22083820edd98509664e53847e51fa483043cd970ab6fab7bc8568f492d086d8cbbf08773e74b0cae21866f643e37ad186e2adcd916444fc765d01a0a3",
    name: "Parity/v1.7.9-stable-12940e4-20171113/x86_64-linux-gnu/rustc1.21.0",
    network: {
      localAddress: "10.60.204.121:51991",
      remoteAddress: "52.64.60.233:30303"
    },
    protocols: {
      eth: {
        difficulty: 1.4884062467491263e+21,
        head: "0x1a5e037c586fc9d129740eca2421a48d1ca73e4d8f100d359ac78c52b9dc6073",
        version: 63
      }
    }
}]

要检查geth使用的端口,发现你自己的enode URI 执行:

> admin.nodeInfo
{
  enode: "enode://611c8642b508b6caa4dfcc842213400ab9efa8df5dd886df93cded69ef28befaa9b1328aa705f4e53dc8df460761e00b19332cbba9e2926de00d5dd9414e08d0@[::]:30303",
  id: "611c8642b508b6caa4dfcc842213400ab9efa8df5dd886df93cded69ef28befaa9b1328aa705f4e53dc8df460761e00b19332cbba9e2926de00d5dd9414e08d0",
  ip: "::",
  listenAddr: "[::]:30303",
  name: "Geth/v1.7.3-stable/darwin-amd64/go1.9.2",
  ports: {
    discovery: 30303,
    listener: 30303
  },
  protocols: {
    eth: {
      difficulty: 17179869184,
      genesis: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
      head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
      network: 1
    }
  }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 201,468评论 5 473
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,620评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,427评论 0 334
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,160评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,197评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,334评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,775评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,444评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,628评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,459评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,508评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,210评论 3 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,767评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,850评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,076评论 1 258
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,627评论 2 348
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,196评论 2 341

推荐阅读更多精彩内容