1

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("http://127.0.0.1:30303");
  const web3 = new Web3(provider);
  resolve(web3);

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

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..

1

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:127.0.0.1:303030")

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

geth attach http://127.0.0.1:8545 -> This is the HTTP provider you must use in Metamask (which uses HTTP provider)

Or, with WebSockets : geth attach ws://127.0.0.1:8546

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.