1

I am importing ethereumjs-wallet in angular4,

import EthereumWallet from 'ethereumjs-wallet';
var wallet = EthereumWallet.generate();
const jsV3 = wallet.toV3(passwd);
the code inside the library shown as below
var privKey = crypto.randomBytes(32)

throws out an error

ERROR Error: Uncaught (in promise): TypeError: crypto.randomBytes is not a function TypeError: crypto.randomBytes is not a function TypeError: crypto.randomBytes is not a function at Function.webpackJsonp.../../../../ethereumjs-wallet/index.js.Wallet.generate

The same problem applies to

  var mnemonic = bip39.generateMnemonic();
  var privateKey = hdkey.fromMasterSeed(mnemonic)._hdkey._privateKey
  const wallet = EthereumWallet.fromPrivateKey(privateKey)
TradePageComponent.html:1 ERROR TypeError: crypto.createHmac is not a function
    at Function.webpackJsonp.../../../../hdkey/lib/hdkey.js.HDKey.fromMasterSeed

(hdkey.js:162) at Function.webpackJsonp.../../../../ethereumjs-wallet/hdkey.js.EthereumHDKey.fromMasterSeed (hdkey.js:17)

how to solve the crypto library ?

1

Crypto npm is deprecated and does not contain any code as such. A dirty has is to replace

var crypto = require('crypto');

with

var crypto = require('crypto-browserify');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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