What is the difference between a Wallet and a JsonRpcSigner?
Asked Answered
S

2

6

On the ethers documentation, it says that the two most commons signers are:

Wallet, which is a class which knows its private key and can execute any operations with it.

JsonRpcSigner, which is connected to a JsonRpcProvider (or sub-class) and is acquired using getSigner

What I'm having trouble understanding is how a JsonRpcSigner is created when the provider is a web3provider (i.e., MetaMask). Doesn't a web3provider know its private key and should therefore return a Wallet when provider.getSigner() is run?

Stanchion answered 5/4, 2022 at 16:49 Comment(0)
C
4

The Wallet singer is used when your ethers.js instance knows the private key directly.

Since MetaMask doesn't share the key with other applications, ethers.js uses the JsonRpcSigner to be able to request the local MetaMask instance over its API to sign the transaction when needed, and then receive the signed transaction back, without ethers.js ever knowing the key.

Comitative answered 5/4, 2022 at 17:34 Comment(0)
L
1

I think the Wallet subclass of abstract signer has both the sign and signMessage methods, but JsonRpcSigner (what you get from provider.getSigner()) does not. The use case is I'm trying to sign a transaction using sign from metamask for instance and then submit it later.

Legendary answered 5/4, 2022 at 17:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.