requestAccount method
Request/Enable the accounts from the current environment.
Returns List of accounts the node controls.
This method will only work if you’re using the injected provider from a application like Metamask, Status or TrustWallet.
It doesn’t work if you’re connected to a node with a default Web3.js provider (WebsocketProvider, HttpProvidder and IpcProvider).
String? currentAddress;
int? currentChain;
// Handle `requestAccount` and store accounts and chain information
connectProvider() async {
if (ethereum != null) {
final accs = await ethereum!.requestAccount();
if (accs.isNotEmpty) {
currentAddress = accs.first;
currentChain = await ethereum!.getChainId();
}
}
}
Implementation
Future<List<String>> requestAccount() async =>
(await request<List<dynamic>>('eth_requestAccounts')).cast<String>();