/
example.dart
79 lines (68 loc) · 2.98 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c), Moneytrack.io authors.
// All rights reserved. Use of this source code is governed by a
// MIT license that can be found in the LICENSE file.
import 'package:tezart/tezart.dart';
// Sample mnemonic
const String mnemonic =
'brief hello carry loop squeeze unknown click abstract lounge figure logic oblige child ripple about vacant scheme magnet open enroll stuff valve hobby what';
// Sample secret key
const String secretKey =
'edskRpwW3bAgx7GsbyTrbb5NUP7b1tz34AvfV2Vm4En5LgEzeUmg3Ys815UDYNNFG6JvrrGqA9CNU2h8hsLVVLfuEQPkZNtkap';
// Sample seed
const String seed = 'edsk3RR5U7JsUJ8ctjsuymUPayxMm4LHXaB7VJSfeyMb8fAvbJUnsa';
///
/// This is a simple example of using tezart
/// In this example, we assume that you are running
/// a tezos blockchain locally at http://localhost:2000
///
/// In the README.md of the project, we provided a command line
/// to help you launch a local blockchain with docker.
///
Future<void> main() async {
/// Generate keystore from mnemonic
var keystore = Keystore.fromMnemonic(mnemonic);
// Sample output of keystore created from mnemonic
print(keystore.secretKey);
// => edskRpwW3bAgx7GsbyTrbb5NUP7b1tz34AvfV2Vm4En5LgEzeUmg3Ys815UDYNNFG6JvrrGqA9CNU2h8hsLVVLfuEQPkZNtkap
print(keystore.publicKey);
// => edpkvGRiJj7mCSZtcTabQkfgKky8AEDGPTCmmWyT1Vg17Lqt3cD5TU
print(keystore.address);
// => tz1LmRFP1yFg4oTwfThfbrJx2BfZVAK2h7eW
/// Generate keystore from secret key
keystore = Keystore.fromSecretKey(secretKey);
// Sample output of keystore created from secretkey
print(keystore.secretKey);
// => edskRpwW3bAgx7GsbyTrbb5NUP7b1tz34AvfV2Vm4En5LgEzeUmg3Ys815UDYNNFG6JvrrGqA9CNU2h8hsLVVLfuEQPkZNtkap
print(keystore.publicKey);
// => edpkvGRiJj7mCSZtcTabQkfgKky8AEDGPTCmmWyT1Vg17Lqt3cD5TU
print(keystore.address);
// => tz1LmRFP1yFg4oTwfThfbrJx2BfZVAK2h7eW
/// Generate keystore from seed
keystore = Keystore.fromSeed(seed);
// Sample output of keystore created from seed
print(keystore.secretKey);
// => edskRpwW3bAgx7GsbyTrbb5NUP7b1tz34AvfV2Vm4En5LgEzeUmg3Ys815UDYNNFG6JvrrGqA9CNU2h8hsLVVLfuEQPkZNtkap
print(keystore.publicKey);
// => edpkvGRiJj7mCSZtcTabQkfgKky8AEDGPTCmmWyT1Vg17Lqt3cD5TU
print(keystore.address);
// => tz1LmRFP1yFg4oTwfThfbrJx2BfZVAK2h7eW
///
/// Transfer
/// In this example, we are using a wallet that has enough tez to make the transfer
/// We make the transfer and monitor the operation
/// All amounts are in µtz
///
final sourceKeystore = Keystore.fromSecretKey(
'edskRpm2mUhvoUjHjXgMoDRxMKhtKfww1ixmWiHCWhHuMEEbGzdnz8Ks4vgarKDtxok7HmrEo1JzkXkdkvyw7Rtw6BNtSd7MJ7');
final destinationKeystore = Keystore.random();
final client = TezartClient('http://localhost:20000');
final amount = 10000;
final operationsList = await client.transferOperation(
source: sourceKeystore,
destination: destinationKeystore.address,
amount: amount,
);
await operationsList.executeAndMonitor();
print(await client.getBalance(address: destinationKeystore.address));
// => 10000
}