1

I'm trying some examples from the wiki, nothing is working:

var web3 = new Web3(Web3.givenProvider || "https://mainnet.infura.io/v3/5d4d4f7190b94eb4893ef4dbdc782255"); web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);

throws:

Uncaught TypeError: this.provider.send is not a function
at s.send (web3.min.js:1)
at _.e [as getBalance] (web3.min.js:1)
at script.js:7

And this:

web3.eth.getBlockNumber().then(console.log);

throws this:

Uncaught TypeError: this.provider.sendAsync is not a function
at s.sendAsync (web3.min.js:1)
at _.e [as getBlockNumber] (web3.min.js:1)
at :1:10

This isn't the only fuctions that don't work, none of the ones I used worked so far. Directly from the wiki. I'm importing:

  • have you tried removing the Web3.givenProvider || statment? Probably an issue with whatever your computer is picking up for that... – Shawn Tabrizi Nov 6 '18 at 22:01
1

I'm guessing that these docs are quite out of date, I've not seen any usage of Web3.givenProvider before. Most sites use window.web3.currentProvider for the browser-provided one, and you'll need to instantiate the URL instance with Web3.providers.HttpProvider. So you'll probably want to do something like:

var web3 = window.web3 ?
  new Web3(window.web3.currentProvider) :
  new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/v3/[infura-id]"));

Unfortunately the web3 docs seem to frequently be incorrect and out of date.

  • Well, this kinda worked. But, it's as you say. The documentation is really really bad and inaccurate. Just switched to Ethers.js. – bruxo00 Nov 6 '18 at 23:03
  • @bruxo00 Can you indicate the page you were following? To try to report and have it fixed. – Ismael Nov 7 '18 at 14:09
  • Seem to work thanks. I'd remove your infura project's id from the url tho :) – ianaz Jan 22 at 8:08
  • Good looking out, edited it. I just used the URL in OP's post, though they should remove it as well. – wbobeirne Jan 23 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.