WEB3JS (以太坊) 查询以太币余额

WEB3JS (以太坊) 查询以太币余额

node js

下载 web3.js npm install web3

infura https://infura.io/ 提供了托管的以太坊节点



let Web3 = require('web3');

let baseurl = 'https://mainnet.infura.io/ < INFURA访问令牌 >' ;

// set the provider you want from Web3.providers

let web3 = new Web3(new Web3.providers.HttpProvider(baseurl));

// 账号地址

  let currentAccount = "";

// 查询以太币余额

web3.eth.getBalance(currentAccount, (err,result) => {

  if (err== null) {

    console.log('~:'+ web3.utils.fromWei(result,'ether'));

  }else  {

    console.log('~error:'+err);

  }

});

你可能感兴趣的:(WEB3JS (以太坊) 查询以太币余额)