> ## Documentation Index
> Fetch the complete documentation index at: https://build.flashnet.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Swap on a Flashnet pool in one signed intent

This walks you from a fresh install to a successful USDB swap. You need a Spark wallet mnemonic and the URL of a Flashnet Execution gateway.

## Install

The SDK is pre-release. Until the mainnet npm publish, install it from a git tag.

Add this to your `package.json`:

```json theme={null}
{
  "dependencies": {
    "@flashnet/sdk": "github:flashnetxyz/ts-sdk#v0.0.0-alpha7",
    "@buildonspark/spark-sdk": "latest"
  }
}
```

Then:

```bash theme={null}
npm install --ignore-scripts
```

`--ignore-scripts` matters. `@flashnet/sdk`'s `prepare` hook runs `rollup -c` against its devDependencies before your installer has linked them, so a plain `npm install` may fail with `Cannot find module 'rollup'`. The `--ignore-scripts` flag avoids that ordering. npm still builds the package on its own pass, so you end up with a working `dist/`.

If you prefer bun and the dist isn't there after install, build it manually:

```bash theme={null}
cd node_modules/@flashnet/sdk && bunx tsc --noEmit && bunx rollup -c
```

Verify by importing one of the clients:

```typescript theme={null}
import { ExecutionClient, TradingClient } from "@flashnet/sdk";
```

## Create the clients

```typescript theme={null}
import { SparkWallet } from "@buildonspark/spark-sdk";
import { ExecutionClient, TradingClient } from "@flashnet/sdk";

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

const execClient = new ExecutionClient(sparkWallet);
await execClient.authenticate();

const trading = new TradingClient(execClient, "regtest");
```

`ExecutionClient` reads the wallet's network and picks up the matching gateway endpoints from a built-in preset. For localnet or a custom deployment, pass an override: `new ExecutionClient(sparkWallet, { gatewayUrl, rpcUrl, chainId })`.

`"regtest"` loads the staging contract preset (Conductor, QuoterV2, V3 factory, position manager, WBTC, Permit2), so swaps, quotes, and liquidity resolve without passing addresses. For another deployment, pass an explicit `TradingConfig` instead.

`authenticate()` derives the Execution-side EVM address from the same identity key that controls the Spark wallet. There is no separate signup, faucet, or funding step.

## Swap BTC for USDB

```typescript theme={null}
const result = await trading.swap({
  assetInAddress: "btc",
  assetOutAddress: process.env.USDB_ADDRESS,
  amountIn: "100000",                    // 100,000 sats in
  minAmountOut: "950000000000000000",    // your quote minus slippage
  fee: 3000,                             // 0.3% Uniswap V3 tier
  withdraw: true,                        // sweep output back to Spark
  useAvailableBalance: true,             // pull amountIn from the Spark wallet
});

console.log("submission id:", result.submissionId);
console.log("intent id:", result.intentId);
```

`useAvailableBalance: true` makes the SDK pull the input from your Spark wallet, run the swap, and dispatch the output back to Spark in one signed intent. Nothing needs to sit on the EVM side before or after.

## What just happened

1. The SDK pulled `100_000` sats from your Spark wallet and sent them to the gateway's deposit address.
2. It bundled that Spark transfer id, the Conductor swap call, and the USDB withdrawal into one canonical intent and signed it with your identity key.
3. The gateway admitted the intent. The sequencer included it once the deposit oracle confirmed the Spark transfer. Validators finalized the block.
4. SparkGateway emitted a `SparkWithdrawal` event for the USDB output. The settlement layer scanned the log and dispatched the matching Spark token transfer back to your Spark wallet.

`trading.swap()` resolves when the gateway admits the intent (status `ACCEPTED`); it does not wait for the block to finalize. Poll the intent to follow it to `FINALIZED`, or watch your Spark wallet for the inbound transfer. See [Intents](/products/execution/intents#status-lifecycle).

## Next steps

<CardGroup cols={2}>
  <Card title="Deposits" href="/products/execution/deposits">
    Move sats and Spark tokens in without swapping.
  </Card>

  <Card title="Withdrawals" href="/products/execution/withdrawals">
    Sweep balances back to Spark on demand.
  </Card>

  <Card title="Deploy your own contract" href="/products/execution/executing">
    Sign and submit arbitrary EVM transactions through `ExecutionClient.execute`.
  </Card>

  <Card title="Reading state" href="/products/execution/reading-state">
    Token info, balances, allowances, fees.
  </Card>
</CardGroup>
