Before you can interact with Flashnet AMM, you need to set up the Flashnet SDK and initialize a client with your wallet. This guide will walk you through the installation and initialization process.

Installation

Install the required packages:
npm install @flashnet/sdk @buildonspark/spark-sdk
# or
yarn add @flashnet/sdk @buildonspark/spark-sdk
# or
bun add @flashnet/sdk @buildonspark/spark-sdk

Initialization

Create a new instance of the Flashnet client with your Spark wallet:
import { FlashnetClient } from '@flashnet/sdk';
import { SparkWallet } from '@buildonspark/spark-sdk';

// Initialize your Spark wallet
const { wallet } = await SparkWallet.initialize({
  mnemonicOrSeed:
    process.env.MNEMONIC,
  options: {
    network: "REGTEST",
  },
});

// Create the Flashnet client
const client = new FlashnetClient(wallet);

await client.initialize();

// The client will automatically:
// - Authenticate with the AMM service
// - Handle all signing and intent generation

Using the Spark wallet from the client

The client can also be used as a regular Spark wallet:
import { FlashnetClient } from '@flashnet/sdk';
import { SparkWallet } from '@buildonspark/spark-sdk';

// Initialize your Spark wallet
const { wallet } = await SparkWallet.initialize({
  mnemonicOrSeed:
    process.env.MNEMONIC,
  options: {
    network: "REGTEST",
  },
});

// Create the Flashnet client
const client = new FlashnetClient(wallet);

await client.initialize();

const invoice = await client.wallet.createLightningInvoice({
  amountSats: 1000000,
  memo: "Test invoice",
});

console.log(invoice);