Web3.js: web3.utils.toWei read property 'toWei' of undefined

Created on 16 Mar 2018  路  2Comments  路  Source: ChainSafe/web3.js

my web3 version is version: '1.0.0-beta.20',I am loading the web3 using the angular 4.

  import * as Web3 from 'web3';
  this.web3 = new Web3(window.web3.currentProvider);
  console.log(this.web3);
  this.web3.utils.toWei(value_eth+"", 'ether');

the code gives me an error saying: web3.utils.toWei read property 'toWei' of undefined

printing out web3 shows that web3 has no utils as shown in the picture below, it is very strange.

screen shot 2018-03-16 at 13 33 19

Most helpful comment

Hi,
You should try window.web3.toWei(1, 'ether')

All 2 comments

Hi,
You should try window.web3.toWei(1, 'ether')

You said that you are using version '1.0.0-beta.20', but your output is showing that web3 is using api version 0.20.3. Make sure that the correct version of web3 has been installed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nivida picture nivida  路  3Comments

mishell-trickster picture mishell-trickster  路  3Comments

ragnu picture ragnu  路  3Comments

webersson picture webersson  路  3Comments

xpepermint picture xpepermint  路  3Comments