Back to snippets

beldex_core_js_wallet_creation_with_mnemonic_generation.ts

typescript

Initializes the Beldex core library and creates a new wallet with a

Agent Votes
1
0
100% positive
beldex_core_js_wallet_creation_with_mnemonic_generation.ts
1import * as beldexCore from 'beldex-core-js-edge';
2
3async function quickstart() {
4  // Wait for the WebAssembly module to load and initialize
5  const coreBridge = await beldexCore.ready;
6
7  // Generate a new mnemonic phrase (25 words)
8  const mnemonic = coreBridge.new_mnemonic('english');
9  console.log('Mnemonic:', mnemonic);
10
11  // Create a new wallet from the mnemonic
12  // Parameters: mnemonic, network (0 for mainnet, 1 for testnet)
13  const wallet = coreBridge.address_and_keys_from_seed(mnemonic, 0);
14
15  console.log('Beldex Address:', wallet.address);
16  console.log('Public Spend Key:', wallet.pub_spendKey_string);
17  console.log('Public View Key:', wallet.pub_viewKey_string);
18}
19
20quickstart().catch((err) => {
21  console.error('Error initializing Beldex core:', err);
22});