-
Notifications
You must be signed in to change notification settings - Fork 30
/
example.dart
60 lines (54 loc) · 1.32 KB
/
example.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
52
53
54
55
56
57
58
59
60
import 'package:alan/alan.dart';
import 'package:alan/proto/cosmos/bank/v1beta1/export.dart' as bank;
void main() async {
// Create a wallet
final networkInfo = NetworkInfo.fromSingleHost(
bech32Hrp: 'desmos',
host: 'localhost',
);
final mnemonic = [
'roast',
'stomach',
'welcome',
'please',
'gauge',
'funny',
'coconut',
'baby',
'bird',
'announce',
'bind',
'jacket',
'title',
'vibrant',
'tomorrow',
'indoor',
'bitter',
'initial',
'ill',
'analyst',
'thought',
'strike',
'answer',
'cotton',
];
final wallet = Wallet.derive(mnemonic, networkInfo);
// 3. Create and sign the transaction
final message = bank.MsgSend.create()
..fromAddress = wallet.bech32Address
..toAddress = 'cosmos1cx7mec8x567xh8f4x7490ndx7xey8lnr9du2qy';
message.amount.add(Coin.create()
..denom = 'uatom'
..amount = '100');
final signer = TxSigner.fromNetworkInfo(networkInfo);
final tx = await signer.createAndSign(wallet, [message]);
// 4. Broadcast the transaction
final txSender = TxSender.fromNetworkInfo(networkInfo);
final response = await txSender.broadcastTx(tx);
// Check the result
if (response.isSuccessful) {
print('Tx sent successfully. Response: $response');
} else {
print('Tx errored: $response');
}
}