I am attempting to connect the frontend of an application to a private chain through Metamask.
As no web3 is injected, the following code is run

const getWeb3 = () => ...
  ... ... ... 
  const provider = new Web3.providers.HttpProvider("");
  const web3 = new Web3(provider);

initWeb3 = async () => {
  try {
     this.web3 = await getWeb3();
     this.accounts = await this.web3.eth.getAccounts();
  } catch (err) {
      alert('Failed to load web3, accounts, or contract');

If I put a console.log() statement after the call to web3.eth.getAccounts() it never gets called, which to me means that the await statement never resolves. What could be causing this? The code runs when interacting with a truffle testnet; but, I cannot get it to run with the private chain..


First, if you specify the provider in the code you do not use Metamask.

Second, the port 30303 is the default port for ethereum node in geth. I would suggest to switch for the RPC port (by default: 8545 on geth).

I explain myself : On geth, by default, if you want to connect a node to another you will use port 30303 -> admin.addPeer("enode://XXXXXXXXX:")

If you want to attach to a node without using a node yourself you can use HTTP provider :

geth attach -> This is the HTTP provider you must use in Metamask (which uses HTTP provider)

Or, with WebSockets : geth attach ws://

Your Answer

