browser library
Support for using dart_web3 with browser clients such as MetaMask.
Example
import 'dart:convert';
import 'dart:html';
import 'dart:typed_data';
import 'package:dart_web3/browser.dart';
import 'package:dart_web3/dart_web3.dart';
Future<void> main() async {
final eth = window.ethereum;
if (eth == null) {
print('MetaMask is not available');
return;
}
final client = Web3Client.custom(eth.asRpcService());
final credentials = await eth.requestAccount();
print('Using ${credentials.address}');
print('Client is listening: ${await client.isListeningForNetwork()}');
final message = Uint8List.fromList(utf8.encode('Hello from dart_web3'));
final signature = await credentials.signPersonalMessage(message);
print('Signature: ${base64.encode(signature)}');
}
Classes
Extensions
- DartEthereum on Ethereum
- This extension provides Dart methods around the raw Ethereum JavaScript object.
- GetEthereum on Window
-
Extension to load obtain the
ethereum
window property injected by Ethereum browser plugins.