Created
November 23, 2023 14:28
-
-
Save jlescalonap/9b04ee928da3cabf0df2eba86579f7e6 to your computer and use it in GitHub Desktop.
How to solve the window.ethereum / window undefined problem in Nextjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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