-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
51 lines (37 loc) · 1.77 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import 'package:ether_dart/ether_dart.dart';
void main() async {
///Create EtherDart without immediate connection
final etherDart = EtherDart();
///Generate memomic phrase (can be called seed phrase (Eg : cow ram pig goat ))
final memonicPhrase = etherDart.generateMemonicPhrase();
print(memonicPhrase);
///Verify seed phrase
if (memonicPhrase != null) {
etherDart.verifyMemonicPhrase(memonicPhrase);
}
///i would expose more api in the future
///Eg - memonicToSeedPhrase and the rest
///Create Wallet from private key
final wallet = etherDart.walletFromMemonicPhrase(memonicPhrase!);
print(wallet?.privateKey);
///Create wallet from private key (NOTE: Wallet from private doesnt contain memonic seed phrase)
final walletFromPrivateKey = etherDart.walletFromPrivateKey(
"0x7bda80e5a0873b022832654346b5313063265a2d627ff8609bcb35d714e641e0");
print(walletFromPrivateKey?.address);
///This my own RpcHost- you can create us with quickNode also
final myHost =
"https://bold-multi-arrow.discover.quiknode.pro/2440878aa102c59f436e9e5d84e9cea302a47356/";
///Connect ether to a provider
///Client in this case is an http client (Used in sending request to your rpc host)
final provider = etherDart.connectProvider(Web3Client(myHost, Client()));
///Use the provider to perform different action
///Eg - getGasPrice
///Eg - send transaction and the rest
final gasPrice = await provider.getGasPrice();
print("Ether gas price ${gasPrice.getInWei}");
///Create an EtherDart with immediate connection
final etherDartWithConnect = EtherDart.connect(Web3Client(myHost, Client()));
final gasPriceWithConnect =
await etherDartWithConnect.provider?.getGasPrice();
print("Ether gas price with Connect ${gasPriceWithConnect?.getInWei}");
}