ethers.js
ethers.js copied to clipboard
ethers.Wallet not working on node v17,18
Ethers Version
5.6.8
Search Terms
wallet, mnemonic, private key
Describe the Problem
Issue: Wallet intialization not working in Node v17.x.x or v18.x.x Code:
const ethers = require("ethers");
(async() => {
const pvKey = ethers.ethers.Wallet.createRandom().privateKey;
console.log(pvKey);
})();
It throws this error:
node:internal/crypto/hash:67
this[kHandle] = new _Hash(algorithm, xofLen);
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at createHash (node:crypto:135:10)
at ripemd160 (/Users/vanxh/codes/bitpack/extension/node_modules/@ethersproject/sha2/lib/sha2.js:11:43)
at new HDNode (/Users/vanxh/codes/bitpack/extension/node_modules/@ethersproject/hdnode/lib/index.js:74:110)
at Function.HDNode._fromSeed (/Users/vanxh/codes/bitpack/extension/node_modules/@ethersproject/hdnode/lib/index.js:211:16)
at Function.HDNode.fromMnemonic (/Users/vanxh/codes/bitpack/extension/node_modules/@ethersproject/hdnode/lib/index.js:218:23)
at Function.Wallet.fromMnemonic (/Users/vanxh/codes/bitpack/extension/node_modules/@ethersproject/wallet/lib/index.js:235:43)
at /Users/vanxh/codes/bitpack/extension/z.js:7:41
at Object.<anonymous> (/Users/vanxh/codes/bitpack/extension/z.js:13:3)
at Module._compile (node:internal/modules/cjs/loader:1097:14) {
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
@alcuadrado already reported!
Hey @ricmoo,
I think this will become increasingly more common now that Hardhat supports Node 18.
We had some instances of this issue internally and fixed it by upgrading to the latest ethereum-cryptography
. I know that may not be something you are looking to do, but maybe @noble/hashes
?
FYI: confirmed this issue. Working on it now.
As a note for those that need a quick fix, the RIPEMD-160 was removed from the default crypto provider, you can re-enable it on the node command line using --openssl-legacy-provider
.
I'll use the software implementation in hash.js
starting in v5.7.0
so this won't be necessary after that release.