我使用flutter_web3包将flutter web应用程序连接到metamask,但是我如何将事务发送到metamask让用户付费呢?我试着根据包文档编写代码,但是不起作用。
连接到元掩码代码
import 'package:flutter/cupertino.dart';
import 'package:flutter_web3/flutter_web3.dart';
class MetaMaskProvider extends ChangeNotifier {
static const operatingChain = 4;
String currentAddress = '';
int currentChain = 80001;
bool get isEnabled => ethereum != null;
bool get isInOperatingChain => currentChain == operatingChain;
bool get isConnected => isEnabled && currentAddress.isNotEmpty;
//final polygonWc = WalletConnectProvider.polygon();
Future<void> connect() async {
if (isEnabled) {
final accs = await ethereum!.requestAccount();
if (accs.isNotEmpty) currentAddress = accs.first;
currentChain = await ethereum!.getChainId();
notifyListeners();
}
}
clear() {
currentAddress = '';
currentChain = 80001;
notifyListeners();
}
init() {
if (isEnabled) {
ethereum!.onAccountsChanged((accounts) {
clear();
});
ethereum!.onChainChanged((accounts) {
clear();
});
}
}
}
连接功能将打开元掩码,用户可以选择一个帐户并批准连接,类似于我如何发送事务到元掩码。
1条答案
按热度按时间yhived7q1#
这就是: