Skip to content

Lesson 7 - what's the purpose of connect() #1963

Answered by krakxn
nsawit asked this question in Q&A
Discussion options

You must be logged in to vote

It is so that our instance of the decrypted wallet here

let wallet = new ethers.Wallet.fromEncryptedJsonSync(
    encryptedJson,
    process.env.PSW
  );

can then be instead used to get an instance of the new wallet; which—in this case—is the same decrypted wallet but connected to the provider you provide.

From docs:

"Creates a new Wallet instance from an existing instance, connected to a new provider."

"A connected Provider which allows the wallet to connect to the Ethereum network to query its state and send transactions, or null if no provider is connected.

To change the provider, use the connect method, which will return a new instance of the Wallet connected to the provider."

Entire…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@othaime-en
Comment options

@krakxn
Comment options

Answer selected by nsawit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants