3

while creating new account from angular using web3

  1. personal.newAccount function() undefined
import { 
Injectable } from 
'@angular/core';

import { 
User } from 
'./login/user';

const Web3=require('web3');

declare let
require: any;

declare let
window: any;



let tokenAbi =
require('./tokenContract.json');



@Injectable()

export class
ContractService {



private contAbi=require('./tokenContract.json');

private contAddr='0xadd2b6f750e0a05b25840ac9037365ce79f6a475';

web3:any;

private contract:any;

constructor() {



if (typeof
this.web3 !==
'undefined') {

this.web3 =
new Web3(this.web3.currentProvider);

} else {

this.web3 =
new Web3(new
Web3.providers.HttpProvider("http://localhost:8545"));

}

console.log(this.web3._provider);

this.web3.eth.getAccounts((err,
accs) => {

if (err !=
null) {

alert('There was an error fetching your accounts.');

return;

}



if (accs.length ===
0) {

alert('Couldn\'t get any accounts! Make sure your Ethereum client is configured correctly.');

return;

}

console.log(accs[0]);

this.web3.eth.defaultAccount =
accs[0];


});

this.contract=new
this.web3.eth.Contract(this.contAbi,this.contAddr);

// console.log(this.contract.methods.greet().call({from:this.web3.eth.defaultAccount,gas:0x27100},function(error,result){

// console.log(error);

// console.log(result);

// }));


}






public register(user:User){

user.address=this.web3.personal.newAccount(user.password);


}



}
3
  • Hi there. Can you include the exact code you're using for this? Apr 16, 2018 at 14:15
  • Hi Richard pls check the question, I have update it Apr 17, 2018 at 4:24
  • What's the error?
    – abed
    Feb 18, 2019 at 22:01

1 Answer 1

0

Your web3 talks to a node over RPC. If it is a geth node, the personal api is not exposed/enabled by default for security reasons.

Exercise caution.

You might enable it with geth --rpcapi eth,web3,personal in addition to your other parameters.

Hope it helps.

1
  • Hi Rob, still my problem is not solved, I have updated the question with the code, please check if I am going right? Apr 17, 2018 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.