Fix: correction for how providers and accounts get created when the chain changes#18
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue with provider and account recreation when the blockchain network changes in a Web3 React application. The fix addresses an ethers.js v6 limitation where providers throw errors if used after the network has changed.
Changes:
- Updated the web3 provider creation logic to depend on
web3ChainId, ensuring the provider is recreated when the chain changes - Removed redundant
loadWeb3Accounts()call fromonChainChangedcallback to rely on the useEffect trigger instead - Added extensive console.log debugging statements throughout the codebase
- Updated dependencies including ethers, @base-org/account, React types, and build tools
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Web3AccountContext.tsx | Core fix: Added web3ChainId dependency to web3 provider useMemo and removed redundant loadWeb3Accounts call; added debug logging |
| src/useWeb3Transaction.ts | Added console.log statements for transaction debugging |
| package.json | Updated dependencies: ethers (6.15.0→6.16.0), @base-org/account (2.3.1→2.5.1), React types, and build tools |
Comments suppressed due to low confidence (2)
src/Web3AccountContext.tsx:298
- Console.log statements should be removed before merging to production. These debugging statements will add unnecessary noise to the browser console in production environments.
throw new Error('No web3 provider available to switch chain');
src/Web3AccountContext.tsx:327
- Console.log statements should be removed before merging to production. These debugging statements will add unnecessary noise to the browser console in production environments.
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Screenshots:
Checklist: