Skip to main content
Create and initialize Spark wallets with full key control.
Create a WalletCreate a Wallet

Initialize Wallet

The initialize method is the primary way to create or restore a Spark wallet. Leave mnemonicOrSeed blank to generate a new wallet, or provide an existing mnemonic seed phrase to import an existing wallet.

Essential Wallet Operations

After creating your wallet, you can perform these essential operations Gets the identity public key of the wallet
Gets the Spark address of the wallet
Gets the current balance of the wallet, including Bitcoin and token balances.
Initialization starts an active wallet: it subscribes to events, claims incoming transfers, and runs periodic maintenance such as token-output optimization. This also applies to a wallet used only to create invoices for other users. For queries alone, use SparkReadonlyClient. Automatic token-output optimization is enabled by default. To disable that task, pass tokenOptimizationOptions: { enabled: false } inside the initialization options. The wallet still subscribes to events and claims incoming transfers; this is not a read-only mode. Call cleanup() when the wallet is no longer needed. It clears background intervals, aborts streams, removes listeners, and closes connections. Open resources can keep a Node.js script alive after its main function finishes.

Network Configuration

Spark supports both mainnet and regtest networks:
Always use REGTEST for development and testing. Only use MAINNET for production applications with real Bitcoin.
Account number defaults differ by network. REGTEST defaults to account 0, MAINNET defaults to account 1. If you test on REGTEST without specifying accountNumber, then deploy to MAINNET with the same mnemonic, your wallet will be empty because funds are on a different account. Always explicitly set accountNumber for consistent behavior.

Account Derivation

You can create multiple accounts from the same mnemonic by specifying different account numbers:

API Reference

Wallet Methods: