1

I have the following code to create my own wallet:

var ethers = require('ethers')

    let data = {"address":....}
    var password = "***";
    var json = JSON.stringify(data);
    ethers.Wallet.provider = new ethers.providers.Web3Provider(web3.currentProvider);
    ethers.Wallet.fromEncryptedWallet(json, password).then(function (wallet) {
        console.log("Wallet address: " + wallet.address);
    });

But it does not work because: TypeError: ethers.Wallet.fromEncryptedWallet is not a function

Am I missing something?

1
  • Maybe this used to work under ethers^3.0.15? Dec 18, 2018 at 9:34

2 Answers 2

1

It seems there's a problem with documentation

The correct function is Wallet.fromEncryptedJson

From their unit test

return Wallet.fromEncryptedJson(test.json, test.password).then(...
2
  • it is the same that Im doing, previously Wallet is defined as "ethers.Wallet" Nov 9, 2018 at 21:53
  • @sapiensapiens There's a small difference: fromEncryptedWallet ---> fromEncryptedJson.
    – Ismael
    Nov 10, 2018 at 4:50
0

This works for me.

 const encryptedJson = fs.readFileSync('./.encryptedKey.json', 'utf8');
  let wallet = ethers.Wallet.fromEncryptedJsonSync(
    encryptedJson,
    process.env.PRIVATE_KEY_PASSWORD
  );
  wallet = wallet.connect(provider);

Don't bother adding the new" keyword before "ethers.Wallet(...) that will create an error in ethers v6.11.0"

Your Answer

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

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