环境
os:centos7.6
nodejs:v8.11.4
安装web3.js
npm install ethereum/web3.js --save
web3.js接口测试
- 进入node控制台
node
- 定义web3变量
注意>号不是命令的一部分
//使用web3模块
> var Web3 = require('web3')
//创建web3实例(假设burrow rpc监听端口为26860)
> var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:26860"));
- 测试
> web3.eth.blockNumber
133
> web3.eth.getBlock(133)
{ sha3Uncles: '0x0',
transactionsRoot: '0x8c29ac4e536c3b6528f4101247468aeef57df80748dfc9d849f8d5e922b908d2',
parentHash: '0x8c29ac4e536c3b6528f4101247468aeef57df80748dfc9d849f8d5e922b908d2',
miner: '0x5375fb6781c0c9ba1a35b92786554ecac9a3d3e2',
difficulty: BigNumber { s: 1, e: 0, c: [ 0 ] },
gasUsed: 0,
timestamp: 1586266097,
transactions: [],
number: 133,
hash: '0x8c29ac4e536c3b6528f4101247468aeef57df80748dfc9d849f8d5e922b908d2',
uncles: [],
receiptsRoot: '0x8c29ac4e536c3b6528f4101247468aeef57df80748dfc9d849f8d5e922b908d2',
extraData: '0x0',
stateRoot: '0x8c29ac4e536c3b6528f4101247468aeef57df80748dfc9d849f8d5e922b908d2',
totalDifficulty: BigNumber { s: 1, e: 0, c: [ 0 ] },
size: 0,
gasLimit: 9007199254740991,
nonce: '0x0000000000000000',
logsBloom: '0x0' }