Lesson 10 : TypeError: Cannot read properties of undefined (reading 'length') #5723
-
Hi Guys! I'm going through lesson 10 of the course and I switched to a one-hour tutorial in which Patrick explains six different ways to connect your App to metamask. Now I'm doing the third with React (nextjs-web3-react) and so far I've done everything right but getting this error here :
Here is my code import "@/styles/globals.css";
import { Web3ReactProvider } from "@web3-react/core";
import { Web3Provider } from "@ethersproject/providers"; //Not full ethers
const getLibrary = (provider) => {
return new Web3Provider(provider);
};
export default function App({ Component, pageProps }) {
return (
<Web3ReactProvider getLibrary={getLibrary}>
<Component {...pageProps} />
</Web3ReactProvider>
);
} index.js : import Head from "next/head";
import Image from "next/image";
import styles from "@/styles/Home.module.css";
import { useWeb3React } from "@web3-react/core";
import { InjectedConnector } from "@web3-react/injected-connector";
const injected = new InjectedConnector();
export default function Home() {
const { active, activate, library: provider, } = useWeb3React();
async function connect() {
try {
await activate(injected);
} catch (e) {
console.log(e);
}
}
return (
<div className={styles.description}>
{active ? (
<>
"Connected! " <button onClick={() => execute()}>Execute</button>
</>
) : (
<button onClick={() => connect()}>Connect</button>
)}
</div>
);
} I've tried a lot already, and it seems the problem's coming from the getLibrary but don't know what's wrong. I'll be grateful for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
@Bobodilo Please copy paste the terminal issue here above and below that add backticks ``` |
Beta Was this translation helpful? Give feedback.
@alymurtazamemon I fixed the issue. It was a version conflict in my dependencies. I downgraded everything to Pactrick's versions and also had to downgrade my node.js to v16. Now it's working fine. But when I run the Execute function I'm getting this error here in my hardhat node :
Error: Transaction reverted: function selector was not recognized and there's no fallback function
I wonder what's the issue here.
index.js :