Skip to content

3 · Create wallets

Next you create Alice’s and Bob’s wallets. Both are HD wallets, each made from a fresh BIP-39 mnemonic.

libspiffy generates no keys. Pass CreateWalletCommand a mnemonic, xpriv, wif or xpub (an xpub gives a watch-only wallet). Here you generate a mnemonic with DartSVCryptoService, which libspiffy exports:

bin/first_payment.dart (step 3)
// Step 3: create two wallets, each from a fresh mnemonic.
final crypto = DartSVCryptoService();
for (final walletId in ['alice', 'bob']) {
final mnemonic = await crypto.generateMnemonic();
final created = await coordinator.ask(CreateWalletCommand(
walletId: walletId, name: walletId, mnemonic: mnemonic));
print('Created $walletId (root address ${created.rootAddress})');
}
  • The reply is the command’s WalletCreatedEvent. ask returns it only when the wallet was created.
  • On failure, ask throws a CoordinatorFailure. Its message says why, and its event holds the failed reply.
  • The mnemonic is the wallet’s backup. This tutorial throws it away. A real app shows it to the user or stores it in the platform keystore.
Created alice (root address mgK27BXo3QodQsiRa8gBLF46jYnsY78Yvm)
Created bob (root address mxSu1TZsACrkLcoUDBVjwqDj7qHdYwM2nQ)

Your addresses will differ: each run makes new mnemonics.

Each wallet now has its own event stream in the journal, starting with wallet.created. One libspiffy actor system holds both wallets, kept apart by walletId.

Next: fund Alice →