[Ethereum] create a new account using web3.js with angular

angular2go-ethereumweb3js

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 🙂

Best Answer

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

Related Topic