Skip to content

Instantly share code, notes, and snippets.

@jlescalonap
Created November 23, 2023 14:28
Show Gist options
  • Save jlescalonap/9b04ee928da3cabf0df2eba86579f7e6 to your computer and use it in GitHub Desktop.
Save jlescalonap/9b04ee928da3cabf0df2eba86579f7e6 to your computer and use it in GitHub Desktop.
How to solve the window.ethereum / window undefined problem in Nextjs
useEffect(() => {
if (
typeof window !== 'undefined' &&
typeof window.ethereum !== 'undefined'
) {
const provider = new ethers.providers.Web3Provider(
window.ethereum as any
);
// @ts-ignore
setSigner(provider.getSigner());
}
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment