1

From this tutorial, I learned the RPC URL for BSC Testnet is https://data-seed-prebsc-1-s1.binance.org:8545, but when I use it with web3.js like:

const web3 = new Web3('https://data-seed-prebsc-1-s1.binance.org:8545');

I get Module not found: Error: Can't resolve 'stream'. I am coding for a frontend, so what's the issue?

1 Answer 1

2

When connecting to node you need to select the provider type, examples - HttpProvider, WebsocketProvider, and IpcProvider . In your case just change:

new Web3('https://data-seed-prebsc-1-s1.binance.org:8545');

To:

new Web3(new Web3.providers.HttpProvider('https://data-seed-prebsc-1-s1.binance.org:8545'))
4
  • I was following this tutorial which says const web3 = new Web3(rpcURL) should work. I tried your proposed solution and got the same error in my original post.
    – abc
    Commented Jan 13, 2022 at 6:50
  • Something is definelly wrong at your side. Check my sample code at pastebin.com/Mktuz8qA , I'm using latest web3 version 1.6.1 and I added web3.eth.getBlockNumber function just to see if my web3 instance is correctly reading the blockchain data and it is. Commented Jan 13, 2022 at 7:21
  • Could it be that I am trying to do this in a browser? That is where I would like to fetch the blockchain data.
    – abc
    Commented Jan 13, 2022 at 7:43
  • 1
    Yes, this is the issue. You can use this tool browserify.org which compiles all the javascript code which is not supported by the browsers into a "bundled" js file. Commented Jan 13, 2022 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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