[Ethereum] TypeError: Cannot read property ‘fromWei’ of undefined

web3js

My below code is working fine

Web3 = Require('web3');
const walletAddress = '0x8690F1feff62008A396B31c2C3f380bD0Ca6d8b8';
const web3 = new Web3(new Web3.providers.HttpProvider(testnet));
var balance = web3.eth.getBalance(walletAddress); //Will give value in.
balance = web3.toDecimal(balance);

But when I run:

web3.utils.fromWei(balance,'ether')

It throws an error:

"TypeError: Cannot read property 'fromWei' of undefined"

I am using Web3 0.19.1 and node 10.15.1.

Best Answer

With web3.js v0.x, use web3.fromWei.

With web3.js v1.x, use web3.utils.fromWei.

Related Topic