Ethereum: TypeError: Cannot read properties of undefined (reading ‘Web3Provider’)

I see you get a mistake associated with the component Web3provider. I’ll help you prevent it.

The question is that the component “Web3Provider” expects that the ‘service provider’ will be transferred as a support, but in your code you are trying to get it directly from “Contractabi” and “Contractaddress”.

Here is an updated version of your code with the necessary changes:

`JSX

Import React, {Useeffect, Usestate} from “ReAct”;

Import {ethers} from “ethers”;

Import {Agreement Both, Contracting} from ‘../utils/Constants’;

Const Ethereum = () => {

Const [accounts, setaccounts] = usestate ([]);

Useeffect (() => {

// Set the service provider and get the accounts

Const Provider = New Ethers.providers.Web3provider (Window.ethereum);

Const Contalist = Expect a service provider.

Setaccounts (list of accounts);

// If no accounts are found, try to manually connect to the Ethereum network

if (account.lendy === 0) {

Console.log (“The accounts were not found.”);

}

}, []);

return (

ethereum

Ethereum: TypeError: Cannot read properties of undefined (reading 'Web3Provider')

{/ Your REACT app content here /}

);

};

export default Ethereum;

`

In this updated version, I have added a “USESTATE” hook to save the account list. When the component is installed, it tries to connect to the Ethereum network using the service provider and obtain the signed accounts. If the accounts are not found, it records the message.

The main difference is that we are now transferring the object “Provider” object as a support to the Ethereum component, instead of trying to directly access it from Contractabi and Contractaddress.

Make sure you install Ethers.Js ', installing NPM Install Ethers or Yarn Add Ethers’ Project Directory.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top