@@ -19,6 +19,7 @@ function App() {
19
19
} , [ web3Context . providers . length ] ) ;
20
20
21
21
const [ chainId , setChainId ] = useState < bigint | undefined > ( undefined ) ;
22
+ const [ networkId , setNetworkId ] = useState < bigint | undefined > ( undefined ) ;
22
23
useEffect ( ( ) => {
23
24
if ( web3Context . currentProvider === undefined ) {
24
25
return ;
@@ -30,13 +31,15 @@ function App() {
30
31
setChainId ( newId ) ;
31
32
}
32
33
33
- function updateProviderChainId ( newId : ProviderChainId ) {
34
+ function updateProviderIds ( newId : ProviderChainId ) {
34
35
setChainId ( BigInt ( newId ) ) ;
36
+ web3Context . web3 . eth . net . getId ( ) . then ( setNetworkId ) ;
35
37
}
36
38
37
39
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 ) ;
40
43
} , [ web3Context . currentProvider , web3Context . web3 . eth ] ) ;
41
44
42
45
return (
@@ -116,6 +119,7 @@ function App() {
116
119
) : null }
117
120
< h2 > Network Details</ h2 >
118
121
< div > Chain ID: { `${ chainId } ` } </ div >
122
+ < div > Network ID: { `${ networkId } ` } </ div >
119
123
< AccountProvider >
120
124
< Accounts > </ Accounts >
121
125
</ AccountProvider >
0 commit comments