getChainId method

Future<int> getChainId()

Returns chain id in int


String? currentAddress;
int? currentChain;

connectProvider() async {
  if (ethereum != null) {
    final accs = await ethereum!.requestAccount();

    if (accs.isNotEmpty) {
      currentAddress = accs.first;
      currentChain = await ethereum!.getChainId();
    }
  }
}

Implementation

Future<int> getChainId() async =>
    int.parse((await request('eth_chainId')).toString());