控制台

控制台能以IPC的方式直接连接区块链节点进程。使用控制台,能直接查看到区块链上的信息。若需要更直观更全面的区块链数据展现,请使用FISCO-BCOS的区块链浏览器。

登陆控制台

连接节点的data目录下的geth.ipc文件。

  1. ethconsole /mydata/node0/data/geth.ipc

登录成功,可看到successful字样。

  1. Connecting to node at /mydata/nodedata-1/data/geth.ipc
  2. Connection successful.
  3. Current block number: 37
  4. Entering interactive mode.
  5. >

查看区块

如查看块高为2的区块

  1. web3.eth.getBlock(2,console.log)

可得到相应的区块信息

  1. > null { author: '0x0000000000000000000000000000000000000000',
  2. difficulty: { [String: '1'] s: 1, e: 0, c: [ 1 ] },
  3. extraData: '0xd78095312e302b2b302d524c696e75782f672b2b2f496e74',
  4. gasLimit: 2000000000,
  5. gasUsed: 33245,
  6. genIndex: '0x0',
  7. hash: '0xa3c2b1eda74f26c688e78bffcc71c8561e49dc70fbfbd71b85c3b79a2c16bc81',
  8. logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  9. miner: '0x0000000000000000000000000000000000000000',
  10. number: 2,
  11. parentHash: '0x96d095047e68d4db8ae0c74638cf6365d5ee7fbc329d50a5a78a85189e1b105e',
  12. receiptsRoot: '0xb668c383b2ee76f9e2d0a8b0d9b301fb825896a9a597268ca3cbdd979c4a53da',
  13. sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
  14. size: 71,
  15. stateRoot: '0x20993fb96c5a26eb9f158c194bcd4da845afde2c2095e359259001279de23ec2',
  16. timestamp: 1513087469641,
  17. totalDifficulty: { [String: '2'] s: 1, e: 0, c: [ 2 ] },
  18. transactions: [ '0x63749a62851b52f9263e3c9a791369c7380acc5a9b6ee55dabd9c1013634e355' ],
  19. transactionsRoot: '0xc9c0b09f236fba3bad81f6fb92b9ca03b6ccb1aaf53ef600621c0a0fd0fd4bb1',
  20. uncles: [] }

查看交易

根据交易哈希查看交易。如,使用之前调用HelloWord的合约的交易哈希。

  1. web3.eth.getTransaction('0x63749a62851b52f9263e3c9a791369c7380acc5a9b6ee55dabd9c1013634e355',console.log)

可得到相应的交易信息

  1. > null { blockHash: '0xa3c2b1eda74f26c688e78bffcc71c8561e49dc70fbfbd71b85c3b79a2c16bc81',
  2. blockNumber: 2,
  3. from: '0x04804c06677d2009e52ca96c825d38056292cab6',
  4. gas: 30000000,
  5. gasPrice: { [String: '0'] s: 1, e: 0, c: [ 0 ] },
  6. hash: '0x63749a62851b52f9263e3c9a791369c7380acc5a9b6ee55dabd9c1013634e355',
  7. input: '0x4ed3885e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b48656c6c6f576f726c6421000000000000000000000000000000000000000000',
  8. nonce: 67506452,
  9. to: '0x1d2047204130de907799adaea85c511c7ce85b6d',
  10. transactionIndex: 0,
  11. value: { [String: '0'] s: 1, e: 0, c: [ 0 ] } }

查看交易回执

根据交易哈希查看交易回执。如,使用之前调用HelloWord的合约的交易哈希。

  1. web3.eth.getTransactionReceipt('0x63749a62851b52f9263e3c9a791369c7380acc5a9b6ee55dabd9c1013634e355',console.log)

可得到相应的交易回执

  1. > null { blockHash: '0xa3c2b1eda74f26c688e78bffcc71c8561e49dc70fbfbd71b85c3b79a2c16bc81',
  2. blockNumber: 2,
  3. contractAddress: '0x0000000000000000000000000000000000000000',
  4. cumulativeGasUsed: 33245,
  5. gasUsed: 33245,
  6. logs: [],
  7. transactionHash: '0x63749a62851b52f9263e3c9a791369c7380acc5a9b6ee55dabd9c1013634e355',
  8. transactionIndex: 0 }

查看合约代码

根据交易合约地址查看合约。如,用之前部署的HelloWorld合约地址。

  1. web3.eth.getCode('0x1d2047204130de907799adaea85c511c7ce85b6d',console.log)

可以得到HelloWorld的合约二进制代码

  1. > null '0x60606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680634ed3885e146100485780636d4ce63c146100a557600080fd5b341561005357600080fd5b6100a3600480803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610133565b005b34156100b057600080fd5b6100b861014d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f85780820151818401526020810190506100dd565b50505050905090810190601f1680156101255780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b80600090805190602001906101499291906101f5565b5050565b610155610275565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101eb5780601f106101c0576101008083540402835291602001916101eb565b820191906000526020600020905b8154815290600101906020018083116101ce57829003601f168201915b5050505050905090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061023657805160ff1916838001178555610264565b82800160010185558215610264579182015b82811115610263578251825591602001919060010190610248565b5b5090506102719190610289565b5090565b602060405190810160405280600081525090565b6102ab91905b808211156102a757600081600090555060010161028f565b5090565b905600a165627a7a7230582021681cb0ea5b1c4364a4f5e37f12e84241310a74ee462b1a19658b3acc26c6cb0029'

查看节点连接

执行

  1. //ethconsole版本不同命令稍有不同
  2. web3.admin.getPeers(console.log)
  3. //或
  4. web3.admin.peers(console.log)

可看到连接了其它的节点

  1. > null [ { caps: [ 'eth/62', 'eth/63', 'pbft/63' ],
  2. height: '0x25',
  3. id: 'b5adf6440bb0fe7c337eccfda9259985ee42c1c94e0d357e813f905b6c0fa2049d45170b78367649dd0b8b5954ee919bf50c1398a373ca777e6329bd0c4b82e8',
  4. lastPing: 0,
  5. name: 'eth/v1.0/Linux/g++/Interpreter/RelWithDebInfo/0/',
  6. network: { remoteAddress: '127.0.0.1:30403' },
  7. notes: { ask: 'Nothing', manners: 'nice', sync: 'holding & needed' } } ]