[Ethereum] Uncaught Error: Cannot find module ‘web3-eth-personal’

contract-development

I have these two lines of code to unlock the default account,
But i keep on getting error , tough the require path points to proper directory of web3-eth-personal,

var personal = require('./node_modules/web3-eth-personal/');
personal.unlockAccount(web3.eth.defaultAccount)

The Error:

web3.min.js:1 Uncaught Error: Cannot find module
'./node_modules/web3-eth-personal/'
at o (web3.min.js:1)
at o (web3.min.js:1)
at Index2.html:49

The thing is that iam able to call a function which reads value from contract, but trying to set value in contract is problem. my contract is on Ropsten test network.

Please guide.

Best Answer

Try for this:

npm install web3-eth-account --save

npm install web3-eth-personal --save

npm install web3 --save

var Accounts = require('web3-eth-accounts');
var Personal = require('web3-eth-personal');
var Web3 = require('web3');

var accounts = new Accounts(Constant.ETHnodeURL.connectETHnodeWS);
var personal = new Personal(Constant.ETHnodeURL.connectETHnodeWS);
var web3 = new Web3(new Web3.providers.WebsocketProvider(Constant.ETHnodeURL.connectETHnodeWS));

web3.eth.personal.newAccount('privatepassword').then((data) => {
   console.log('Address:'+data);
});
Related Topic