Prerequisites

  • Node.js installed (16 or later)
  • Basic understanding of Bitcoin

Installation

yarn add @buildonspark/spark-sdk

or npm

npm i @buildonspark/spark-sdk

Initialize the Wallet

A wallet needs a mnemonic or a raw seed to be initialized. The initWallet function can take both inputs. If none is provided, the wallet will generate a mnemonic for you and will return it. Save it in a secure location.

Mnemonic Phrases

A mnemonic phrase is a human-readable representation of your wallet’s seed. It consists of a sequence of common words that can be converted into the cryptographic keys that control your wallet. Consists of 12 or 24 common words from a standardized list (BIP-39)

Raw Seed

A raw seed is a cryptographic representation of your wallet’s seed. It consists of a sequence of bytes that can be converted into the cryptographic keys that control your wallet.

Mnemonic Best Practices

  • Store offline in multiple secure locations
  • Never share with anyone or store digitally

Raw Seed Best Practices

  • Use cryptographically secure random number generators
  • Ensure sufficient entropy (256 bits recommended)
  • Clear from memory when no longer needed
// import the SparkWallet and Network from the spark-sdk
import { SparkWallet } from "@buildonspark/spark-sdk";
import { Network } from "@buildonspark/spark-sdk/utils";

// Initialize a new wallet instance
const wallet = new SparkWallet(Network.REGTEST); // or Network.MAINNET

// Create wallet from mnemonic
const menmonic_phrase = await wallet.initWallet("optional-mnemonic-or-seed");

console.log("Wallet initialized successfully:", menmonic_phrase);

Next Steps

Now that you’ve created your first wallet, you can:

  1. Fetch your balance
  2. Deposit Bitcoin
  3. Send & Receive on Lightning
  4. Send & Receive on Spark

Security Considerations

  • Always backup your wallet credentials
  • Use secure key phrase storage

Need Help?