the javascript file used to communicate with test-net :
$(document).ready(function(){
if (typeof web3 !== 'undefined'){
console.log('Web3 found');
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
$("#creatAccountSubmit").click(function(){
var count = $("#noOfAccount").val();
for (let index = 0; index < count; index++) {
var accounts = web3.eth.accounts.create();
console.log(accounts);
}
});
});
I am using ganache-cli as a local provider I don't know which web3 version it uses but the package.json file in my project folder seems to use 1.0.0
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"web3": "^1.0.0-beta.30"
}
}
but after running the web page to create an account am getting an error
"TypeError: web3.eth.accounts.create is not a function"
but the node consoles (it uses web3-1.0.0) I can run the same command,
How can I resolve this error, I think changing the web3 version used by ganache-cli will do the task but don't know how to do it?
Best Answer
The account can be created using the following command.
This method generates a new private key and stores it in the key store directory. The key file is encrypted with the given passphrase/password and returns the address of the new account.
Reference :- https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_newaccount