安装web3+bignumber.js+ethereumjs-util
npm i web3 -s
npm i bignumber.js -s
npm i ethereumjs-util -s
code:
const Web3 = require("web3");
const BigNumber = require('bignumber.js');
const Ether = new BigNumber(10e+17);
const EthUtil = require('ethereumjs-util');
let web3 = new Web3(new Web3.providers.HttpProvider('https://api.myetherapi.com/eth'));
let privateKey = '291c09fc38eb9a253ee9e2d8e90c91b4f08cd87aa3d9bf707d5fd54a3b4aa442'
let publicKey = EthUtil.privateToPublic(new Buffer(privateKey, 'hex'));
let addr ="0x"+ EthUtil.publicToAddress(publicKey).toString('hex');
console.log(addr);
web3.eth.getBalance(addr).then(v => {
let ret = new BigNumber(v);
return parseFloat(ret.dividedBy(Ether)).toFixed(2);
}).then(sum => {
console.log(sum);
})