Can anyone answer how to access Web3Provider
from ethers?
Code:
import {ethers} from 'ethers';
const { ethereum } = window as any;
const getEthereumContract = () => {
const provider = new ethers.providers.Web3Provider(ethereum);
const signer = provider.getSigner();
const { Contract } = ethers;
const contract = new Contract(contractAddress, contractABI, signer);
console.log({
provider,
signer,
contract
})
}
Error:
[{
"resource": "/home/yana/Desktop/projects/crypto/client/src/context/TransactionContext.tsx",
"owner": "typescript",
"code": "2339",
"severity": 8,
"message": "Property 'providers' does not exist on type 'typeof import(\"/home/yana/Desktop/projects/crypto/client/node_modules/ethers/lib.esm/ethers\")'.",
"source": "ts",
"startLineNumber": 14,
"startColumn": 33,
"endLineNumber": 14,
"endColumn": 42
}]
The reason is providers doesn't exits on ethers. I am unable to locate the reason as everywhere I had searched the code is right. Also I want to inform I am using TypeScript for my project but the things should work the same way as in JavaScript