How to Create a Signer Object from an Address in ethers.js

ethers.jshardhattesting

I have a list of addresses, and I would like to use them to test my contract in my hardhat ethers project. Normally I get a list of addresses like this:

[a, b, c] = await ethers.getSigners()

but what I want to do is take address 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 and make it into a signer object so I can call:

contract.connect("0x70997970C51812dc3A010C7d01b50e0d17dc79C8").method()

Best Answer

Since a signer can be a Wallet, VoidSigner or JsonRpcSigner, you can use the jsonRpcProvider.getSigner( [ addressOrIndex ] ) which returns a JsonRpcSigner.