I am trying to build an app where user is asked to connect with Ethereum Browser Wallet (Metamask) and in the next step would like ask for the use to sign a message (not signing a transaction).
The plugin that I am using is flutter_web3
This is the code that asks the user to connect with the Ethereum Wallet
my plugin that I use: https://pub.dev/packages/flutter_web3
Future<String> WalletConnect(context) async {
print("Checking Connect Wallet Status");
if (ethereum != null) {
try {
// Prompt user to connect to the provider, i.e. confirm the connection modal
final accs =
await ethereum!.requestAccount(); // Get all accounts in node disposal
accs;
if (accs.isNotEmpty) {
address = accs.first;
//Get first account
currentChain = await ethereum!.getChainId();
print("Chain ID $currentChain");
//print(currentAddress);
}
return address;
} on EthereumUserRejected {
print('User rejected the modal');
return "CONNECT WALLET";
}
} else {
print("Error in Connect");
showMyDialog(context);
return "CONNECT WALLET";
}
}
I tried other plugins but I would like to use the flutter_web3 plugin to make it happen
You will also need to import
import 'package:web3dart/crypto.dart';
from theweb3Dart
package to be able to use thekeccakUtf8
hashing method.provider
is used with a null check to sure there's a connected wallet account.Code for signing a message: