[Ethereum] web3.js library not loading properly

ethereumjsethereumjs-txinstallationnodejsweb3js

I am trying to load web3 library after installing it via command prompt. However, looks like it is not loading properly as it is not showing all the details for Ethereum ecosystem (ex. unitmap of various ether units).

============================================================================

C:\WINDOWS\system32>node -v
v10.6.0

C:\WINDOWS\system32>npm -v
6.1.0

C:\WINDOWS\system32>node

var Web3 = require('web3');
undefined

Web3
{ [Function: Web3]
providers:
{ HttpProvider: [Function: HttpProvider],
IpcProvider: [Function: IpcProvider] } }

var url = "https://mainnet.infura.io/pK8qXfQRfbImxGXdDPfC"
undefined

var web3 = new Web3(url)
undefined

var address = '0x281055Afc982d96fAB65b3a49cAc8b878184Cb16'
undefined

web3.eth.getBalance(address, (err, bal) => {balance = bal})

TypeError: this.provider.sendAsync is not a function
at RequestManager.sendAsync (C:\WINDOWS\system32\node_modules\web3\lib\web3\requestmanager.js:80:19)
at Eth.send [as getBalance] (C:\WINDOWS\system32\node_modules\web3\lib\web3\method.js:141:42)

============================================================================

First, I downloaded web3 via following command, after that I tried to load the library:

============================================================================
C:\WINDOWS\system32> npm install ethereum/web3.js –save
npm WARN system32@1.0.0 No description

npm WARN system32@1.0.0 No repository field.

Is it happening because I haven't specified a repository while doing "npm init" command?

If it is helpful, I have provided the response as well for "npm init" command.

============================================================================

C:\WINDOWS\system32>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (system32)
version: (1.0.0)
description:
git repository:
keywords:
author:
license: (ISC)
About to write to C:\WINDOWS\system32\package.json:

{
  "name": "system32",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "ganache-cli": "^6.1.5",
    "web3": "github:ethereum/web3.js"
  },
  "devDependencies": {
    "mocha": "^5.2.0"
  },
  "scripts": {
    "test": "mocha"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}


Is this OK? (yes) yes

============================================================================

Any advice would be appreciated. Thanks in advance.

Best Answer

I had same issue with npm install web3. but after executed command of • npm install --global --production windows-build-tools, executing npm install web3 without error but when move into node console, require('web3') gets error. finally I found npm install web3 did not download web3.js and web3.min.js. but change to use npm install ethereum/web3.js works for me.

Related Topic