7

2 个回答

 3 years ago
source link: https://learnblockchain.cn/question/1727
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
以太坊私链转账挖矿后仍然不成功,请高手指教;私链启动后ip不是127.0.0.1,不确定是否是这个原因,如果是这个原因怎么解决? | 登链社区 | 技术问答

以太坊私链转账挖矿后仍然不成功,请高手指教;私链启动后ip不是127.0.0.1,不确定是否是这个原因,如果是这个原因怎么解决?

具体操作步骤
一、配置创世区块

{
	"config":{"chainId":15},
	"difficulty":"2000",
	"gasLimit":"2100000",
	"alloc":{
		"AD9E4555F515132aa94626555A14cdff1e86F0df":{"balance":"300000"}
	}
}

二、启动私链

geth --datadir . --networkid 15  console 2>output.log

启动信息如下:

WARN [12-16|18:54:11.754] Sanitizing cache to Go's GC limits     provided=1024 updated=656
INFO [12-16|18:54:11.756] Maximum peer count                       ETH=50 LES=0 total=50
INFO [12-16|18:54:11.756] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [12-16|18:54:11.792] Set global gas cap                       cap=25000000
INFO [12-16|18:54:11.792] Allocated trie memory caches      clean=163.00MiB dirty=164.00MiB
INFO [12-16|18:54:11.792] Allocated cache and file handles         database=/home/yjh/ETHProject/chain_test/geth/chaindata cache=328.00MiB handles=524288
INFO [12-16|18:54:11.972] Opened ancient database                  database=/home/yjh/ETHProject/chain_test/geth/chaindata/ancient
INFO [12-16|18:54:12.023] Initialised chain configuration          config="{ChainID: 15 Homestead: <nil> DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: <nil> EIP158: <nil> Byzantium: <nil> Constantinople: <nil> Petersburg: <nil> Istanbul: <nil>, Muir Glacier: <nil>, YOLO v2: <nil>, Engine: unknown}"
INFO [12-16|18:54:12.023] Disk storage enabled for ethash caches   dir=/home/yjh/ETHProject/chain_test/geth/ethash count=3
INFO [12-16|18:54:12.023] Disk storage enabled for ethash DAGs     dir=/home/yjh/.ethash count=2
INFO [12-16|18:54:12.023] Initialising Ethereum protocol           versions="[65 64 63]" network=15 dbversion=8
INFO [12-16|18:54:12.057] Loaded most recent local header          number=354 hash="702ea3…43085e" td=50067798 age=3h22m47s
INFO [12-16|18:54:12.057] Loaded most recent local full block      number=354 hash="702ea3…43085e" td=50067798 age=3h22m47s
INFO [12-16|18:54:12.057] Loaded most recent local fast block      number=354 hash="702ea3…43085e" td=50067798 age=3h22m47s
INFO [12-16|18:54:12.059] Setting new local account                address=0x55Db8f37a9c6C226cf2eaf88874E68267aDa9fbE
INFO [12-16|18:54:12.059] Setting new local account                address=0x960e9241A17C7e095E8480870D4d381e8a550163
INFO [12-16|18:54:12.059] Loaded local transaction journal         transactions=4 dropped=0
INFO [12-16|18:54:12.060] Regenerated local transaction journal    transactions=4 accounts=2
WARN [12-16|18:54:12.060] Switch sync mode from fast sync to full sync 
INFO [12-16|18:54:12.060] Starting peer-to-peer node               instance=Geth/v1.9.25-stable-e7872729/linux-amd64/go1.15.6
INFO [12-16|18:54:12.204]** New local node record                    seq=20 id=9f7835f47763f20f ip=127.0.0.1 udp=30303 tcp=30303**
INFO [12-16|18:54:12.206] IPC endpoint opened                      url=/home/yjh/ETHProject/chain_test/geth.ipc
INFO [12-16|18:54:12.216] Started P2P networking                   self=enode://05fb77fd38daac2cfc79da9e71c337ddffd2e566dfb8e14aa5828d0dadc4e860a78b67456c46630836367334d2797eb21a6c49b1aac179afbbf7cb2a84356e90@127.0.0.1:30303
INFO [12-16|18:54:12.304] Etherbase automatically configured       address=0x960e9241A17C7e095E8480870D4d381e8a550163
INFO [12-16|18:54:20.996] New local node record                    seq=21 id=9f7835f47763f20f ip=111.200.193.19 udp=56985 tcp=30303
INFO [12-16|18:54:32.216] Looking for peers                        peercount=1 tried=72 static=0

节点信息为

> admin.nodeInfo
{
  enode: "enode://05fb77fd38daac2cfc79da9e71c337ddffd2e566dfb8e14aa5828d0dadc4e860a78b
67456c46630836367334d2797eb21a6c49b1aac179afbbf7cb2a84356e90@111.200.193.19:30303?discport=56985",
  enr: "enr:-J-4QP4DjNwW5496EtMnlXIsTG6p6RYw_n4wzdbHuB50GhqLXrbaOmMl7xeLUdPAU
mniXpyEKG7nBWjk7WjFDo5MJa0Vg2V0aMfGhCE1fqGAgmlkgnY0gmlwhG_IwROJc2VjcDI1NmsxoQIF-3f9ONqsLPx52p5xwzfd_9LlZt-44Uqlgo0NrcToYIN0Y3CCdl-DdWRwgt6ZhHVkcDaCdl8",
  id: "9f7835f47763f20fe1e36f22e04c1ec61f2eb2ea088650ee89ad3fea9e04df9f",
  ip: "111.200.193.19",
  listenAddr: "[::]:30303",
  name: "Geth/v1.9.25-stable-e7872729/linux-amd64/go1.15.6",
  ports: {
    discovery: 56985,
    listener: 30303
  },
  protocols: {
    eth: {
      config: {
        chainId: 15,
        eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000"
      },
      difficulty: 50067798,
      genesis: "0x35ed2d9b249e6d76635f7f9502b6c1377ea5198458b6a3b678ab7b0bbcdd89f8",
      head: "0x702ea3e85c260edd9f2be3c9d7ae3d20c79a64ad44a1cbcb26b4aca61643085e",
      network: 15
    }
  }
}

三、创建了两个账户,通过挖矿都有以太

> web3.fromWei(eth.getBalance(eth.accounts[0]))
1200
> web3.fromWei(eth.getBalance(eth.accounts[1]))
570

四、估计交易 gas 消耗,转账(期间账户解锁成功)生成交易 hash

> eth.estimateGas({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(10,'ether')})
21000
> eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(10,'ether')})
"0x5a3687165263503df5d38db988c0e8c294f3ea2c9999fb13ef39bebbc3e2b529"

五、挖矿

> miner.start(1)
null

log 信息

INFO [12-16|20:18:58.564] Submitted transaction                    fullhash=0x5a3687165263503df5d38db988c0e8c294f3ea2c9999fb13ef39bebbc3e2b529 recipient=0x55Db8f37a9c6C226cf2eaf88874E68267aDa9fbE
INFO [12-16|20:19:00.654] Commit new mining work                   number=375 sealhash="15da0e…0a5a7a" uncles=0 txs=0 gas=0 fees=0 elapsed=40.693ms
INFO [12-16|20:19:07.581] Looking for peers                        peercount=0 tried=111 static=0
INFO [12-16|20:19:13.093] Successfully sealed new block            number=375 sealhash="15da0e…0a5a7a" hash="b4267f…f21604" elapsed=27.515s
INFO [12-16|20:19:13.104] ? block reached canonical chain          number=368 hash="e3095b…1f016d"
INFO [12-16|20:19:13.156] Commit new mining work                   number=376 sealhash="3b4977…82ddd5" uncles=0 txs=0 gas=0 fees=0 elapsed=62.815ms
INFO [12-16|20:19:13.157] Commit new mining work                   number=376 sealhash="3b4977…82ddd5" uncles=0 txs=0 gas=0 fees=0 elapsed=63.778ms
INFO [12-16|20:19:13.158] ? mined potential block                  number=375 hash="b4267f…f21604"
INFO [12-16|20:19:17.760] Looking for peers                        peercount=0 tried=27  static=0
INFO [12-16|20:19:24.819] Successfully sealed new block            number=376 sealhash="3b4977…82ddd5" hash="96e5d3…75b00b" elapsed=11.714s
INFO [12-16|20:19:24.819] ? block reached canonical chain          number=369 hash="cc0b6b…2f7d99"

六、查看收款账户余额

> web3.fromWei(eth.getBalance(eth.accounts[1]))
570
收款账户没收到转账,以太没有变化

七、查看交易信息

> eth.getTransaction("0x5a3687165263503df5d38db988c0e8c294f3ea2c9999fb13ef39bebbc3e2b529")
{
  blockHash: null,
  blockNumber: null,
  from: "0x960e9241a17c7e095e8480870d4d381e8a550163",
  gas: 21000,
  gasPrice: 1000000000,
  hash: "0x5a3687165263503df5d38db988c0e8c294f3ea2c9999fb13ef39bebbc3e2b529",
  input: "0x",
  nonce: 3,
  r: "0x842ec6a9e84e0c782660a6f113159f920c4a4434f5d3fe658b7df3394be1489",
  s: "0x112e3958f814401e6f0681787b689595e7c0150b7176ab23ef97cdacffbb7541",
  to: "0x55db8f37a9c6c226cf2eaf88874e68267ada9fbe",
  transactionIndex: null,
  v: "0x42",
  value: 10000000000000000000
}

八、其它说明
(1)在 geth --datadir . --dev console 2>output.log 下可以转账,启动后 ip 是 127.0.0.1。
(2)在 geth --datadir . --networkid 15 --rpc console 2>output.log 转账也是无法成功。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK