i am trying to create a new account using web3.js with angular 4. Following is my service

`

import { Injectable } from '@angular/core';
import * as Web3 from 'web3';

declare let require: any;
declare let window: any;

@Injectable()
export class ContractsService {
  private web3: any;

  constructor() {
    if (typeof window.web3 !== 'undefined') {
      // Use Mist/MetaMask's provider
      this.web3 = new Web3(window.web3.currentProvider);

      if (this.web3.version.network !== '4') {
        alert('Please connect to the Rinkeby network');
      }
    } else {
      console.warn(
        'Please use a dapp browser like mist or MetaMask plugin for chrome'
      );
    }
  }

  public creatAccount() {
    let acc = this.web3.eth.personal.newAccount('abc123');
    console.log(acc);
  }

}

` but i am having following error.

enter image description here

can anybody please tell me what is wrong with this code? thanks :)

up vote 1 down vote accepted

Try the below code for Account Creation

 public creatAccount() {
     let acc = this.web3.personal.newAccount('abc123');
     console.log(acc);
 }

Refeernce :- https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_newaccount

  • thanks for the answer, now i am getting following error ` RROR Error: The MetaMask Web3 object does not support synchronous methods like personal_newAccount without a callback parameter ` – Shoaib Iqbal Feb 28 at 9:54

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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