关于账户
> 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
}
}
}
网友评论