0

I'm not able to connect metamask with nodejs.

var Web3        = require('web3');
var web3        = new Web3();

if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
 web3 = new Web3(web3.currentProvider);
 } else {
console.log('No web3? You should consider trying MetaMask!');
  }

It is showing the error :

Error: Provider not set or invalid

| improve this question | | | | |
0

I think the second line of your code is wrong. Try to remove this:

var web3        = new Web3();

as per doc this is the right way to create an instance of web3

if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}

https://github.com/ethereum/wiki/wiki/JavaScript-API#adding-web3

| improve this answer | | | | |
  • I tried this one..Its going to the else part (ie;testrpc). All transactions are done and can be viewed in testrpc. I need to do transaction using metamask. – angelmaria Mar 6 '18 at 7:53
  • Metamask is injected to the client. I don't think you can get the provider inside the server side (NodeJS). That code will work well in your UI – mirg Mar 6 '18 at 7:59

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.