How can I get the provider
from a Wallet
when using ethersjs?
I have tried getting the provider through wallet.provider
but this is different from the Ethereum provider which has the send
method.
I have also tried the following:
const network = await wallet.provider.getNetwork();
const provider = new providers.JsonRpcProvider(network);
The JsonRpcProvider
in this case should return a provider object which has the send
method that is different from wallet.provider
. However, the above still doesn't work because I'm not sure how I can convert from the wallet to the provider without losing any information.
Best Answer
If your wallet is connected to the provider you should be able to get the providers object using
wallet.provider
if you are trying to access the send function of the provider try creating a provider with JsonRpcProvider like:
new ethers. providers.JsonRpcProvider(<networkUrl>)
if you are trying to send transaction using ethers provider directly. use
provider.sendTransaction(<signedTransaction>)
this will send your signed Transaction to blockchain