Web3.js: web3 fromWei/toWei is not defined

Created on 22 Aug 2017  路  2Comments  路  Source: ChainSafe/web3.js

Hi,

Version
OS: ArchLinux 4.9
Node: 8.3.0
Web3: beta 18

Instance methods fromWei and toWei of Web3 is not defined.

The following code returns error:

const Web3 = require("web3");
let web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

web3.eth.getAccounts((err, acc) => {
    console.log(acc);
    web3.eth.getBalance(acc[0]).then(
        bal => {
            console.log(web3.fromWei(bal, "ether"));
        }
    )
});

Error

[ '0x20f808C780C64DeC3bfA7fbA9bec83d4ee08bEF1' ]
Unhandled rejection TypeError: web3.fromWei is not a function
    at web3.eth.getBalance.then.bal (/home/munim/codes/eth-test-01/test.js:9:30)
    at tryCatcher (/home/munim/codes/eth-test-01/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/munim/codes/eth-test-01/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/promise.js:497:31)
    at Promise._settlePromise (/home/munim/codes/eth-test-01/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/promise.js:555:18)
    at Promise._settlePromise0 (/home/munim/codes/eth-test-01/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/promise.js:600:10)
    at Promise._settlePromises (/home/munim/codes/eth-test-01/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/promise.js:683:18)
    at Async._drainQueue (/home/munim/codes/eth-test-01/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/async.js:125:16)
    at Async._drainQueues (/home/munim/codes/eth-test-01/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/async.js:135:10)
    at Immediate.Async.drainQueues (/home/munim/codes/eth-test-01/node_modules/web3/packages/web3-core-promievent/node_modules/bluebird/js/release/async.js:16:14)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)

Most helpful comment

fromWei and toWei moved to utils.

Here's the code that works.

web3.utils.fromWei(bal, "ether")

All 2 comments

fromWei and toWei moved to utils.

Here's the code that works.

web3.utils.fromWei(bal, "ether")

please update docs... took sometime to find this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nivida picture nivida  路  3Comments

gabmontes picture gabmontes  路  3Comments

imthatcarlos picture imthatcarlos  路  3Comments

FradSer picture FradSer  路  3Comments

zamoore picture zamoore  路  3Comments