/
getting-started.ts
60 lines (46 loc) · 1.66 KB
/
getting-started.ts
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
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import { Wallet, CoinType, WalletOptions, Utils } from '@iota/sdk';
// Run with command:
// yarn run-example ./wallet/getting-started.ts
// The database path.
const WALLET_DB_PATH = 'getting-started-db';
// A name to associate with the created account.
const ACCOUNT_ALIAS = 'Alice';
// The node to connect to.
const NODE_URL = 'https://api.testnet.shimmer.network';
// A password to encrypt the stored data.
// WARNING: Never hardcode passwords in production code.
const STRONGHOLD_PASSWORD = 'a-secure-password';
// The path to store the account snapshot.
const STRONGHOLD_SNAPSHOT_PATH = 'vault.stronghold';
async function main() {
const walletOptions: WalletOptions = {
storagePath: WALLET_DB_PATH,
clientOptions: {
nodes: [NODE_URL],
},
coinType: CoinType.Shimmer,
secretManager: {
stronghold: {
snapshotPath: STRONGHOLD_SNAPSHOT_PATH,
password: STRONGHOLD_PASSWORD,
},
},
};
const wallet = new Wallet(walletOptions);
// Generate a mnemonic and store its seed in the Stronghold vault.
// INFO: It is best practice to back up the mnemonic somewhere secure.
const mnemonic = Utils.generateMnemonic();
console.log('Mnemonic:' + mnemonic);
await wallet.storeMnemonic(mnemonic);
// Create an account.
const account = await wallet.createAccount({
alias: ACCOUNT_ALIAS,
});
// Get the first address and print it.
const address = (await account.addresses())[0];
console.log(`Address: ${address.address}\n`);
process.exit(0);
}
main();