@@ -19,6 +19,7 @@ function App() {
1919 } , [ web3Context . providers . length ] ) ;
2020
2121 const [ chainId , setChainId ] = useState < bigint | undefined > ( undefined ) ;
22+ const [ networkId , setNetworkId ] = useState < bigint | undefined > ( undefined ) ;
2223 useEffect ( ( ) => {
2324 if ( web3Context . currentProvider === undefined ) {
2425 return ;
@@ -30,13 +31,15 @@ function App() {
3031 setChainId ( newId ) ;
3132 }
3233
33- function updateProviderChainId ( newId : ProviderChainId ) {
34+ function updateProviderIds ( newId : ProviderChainId ) {
3435 setChainId ( BigInt ( newId ) ) ;
36+ web3Context . web3 . eth . net . getId ( ) . then ( setNetworkId ) ;
3537 }
3638
3739 web3Context . web3 . eth . getChainId ( ) . then ( updateChainId ) ;
38- provider . on ( "chainChanged" , updateProviderChainId ) ;
39- return ( ) => provider . removeListener ( "chainChanged" , updateProviderChainId ) ;
40+ web3Context . web3 . eth . net . getId ( ) . then ( setNetworkId ) ;
41+ provider . on ( "chainChanged" , updateProviderIds ) ;
42+ return ( ) => provider . removeListener ( "chainChanged" , updateProviderIds ) ;
4043 } , [ web3Context . currentProvider , web3Context . web3 . eth ] ) ;
4144
4245 return (
@@ -116,6 +119,7 @@ function App() {
116119 ) : null }
117120 < h2 > Network Details</ h2 >
118121 < div > Chain ID: { `${ chainId } ` } </ div >
122+ < div > Network ID: { `${ networkId } ` } </ div >
119123 < AccountProvider >
120124 < Accounts > </ Accounts >
121125 </ AccountProvider >
0 commit comments