I have an app I am working on implementing ethers.js. There are two methods I am using to create a wallet: new ethers.Wallet(privateKey, provider);
and new ethers.Wallet.createRandom();
With creating a random wallet, it doesnt seem like you can give it the provider
like when importing a private key. That is fine, because once you log out and back in at a later time and get the wallet fromEncryptedJson
, both from the private key import, and the creating a random wallet the provider
is now undefined
Initially wallet.provider
from the import account is there, but after logging out (encrypting the wallet) and then logging back in, after getting the wallet from encryption, provider
is not defined. I need the provider at later times in the app, for instance using the method wallet.getTransactionCount();
, this uses the provider, but it is undefined after logging back in. And if I do wallet.provider = provider
I cant re-assign this value as it says its read only.
So is there a way to set the provider when you un-encrypt the wallet?