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

# SDK Quickstart

> Install the Sweepr TypeScript SDK, build an EVM V2 sweep, verify the fee authorization, and send the transaction.

# SDK Quickstart

The easiest way to integrate Sweepr is the TypeScript SDK. For the first release, Sweepr issues partner API keys directly. There is no self-service dashboard yet.

```bash theme={"dark"}
npm install @sweepr/sdk viem
```

## Initialize

```ts theme={"dark"}
import { Sweepr } from '@sweepr/sdk';

const sweepr = new Sweepr({
  apiKey: process.env.SWEEPR_API_KEY!,
  version: 'v2',
});
```

Use `version: 'v2'` for EVM Partner V2 sweeps with on-chain fee splitting. Use `version: 'v1'` for Solana or the off-chain partner accounting path.

## Check Supported Chains

Before showing a chain in your UI, read V2 status and use only chains that are ready for V5 builds:

```ts theme={"dark"}
const { data: status } = await fetch('https://dev-api.sweepr.co/sweepr/v2/status')
  .then((res) => res.json());

const readyChains = status.chains.filter((chain) => chain.readyForV5Builds);
```

The status response includes enabled chains, V5 contract addresses, output tokens, and router allowlists.

## Build a Sweep

Builds should be created from your backend when using a secret key, or from your frontend only when Sweepr issued a public `pk_live` key with allowed origins.

```ts theme={"dark"}
const build = await sweepr.sweep.build({
  chain: 'base',
  wallet: userAddress,
  tokens: [
    {
      mint: '0xTokenAddress',
      amount: '1000000000000000000',
      symbol: 'TOKEN',
      decimals: 18,
    },
  ],
  outputMint: '0xOutputToken',
  slippageBps: 100,
});
```

Use an idempotency key when retrying a build request from your backend:

```ts theme={"dark"}
const idempotencyKey = request.id; // reuse the same key for retries
const build = await sweepr.sweep.build(request, idempotencyKey);
```

## Verify Fee Authorization

Always verify the V2 fee authorization before asking the user to sign Permit2.

```ts theme={"dark"}
const validFeeAuth = await sweepr.evm.verifyFeeAuthorization(build);

if (!validFeeAuth) {
  throw new Error('Invalid Sweepr fee authorization');
}
```

The SDK checks the EIP-712 signature, chain, V5 contract address, deadline, and fee bounds. If you know the expected partner payout wallet, pass it as an additional check:

```ts theme={"dark"}
const validFeeAuth = await sweepr.evm.verifyFeeAuthorization(build, {
  expectedPartnerRecipient: '0xPartnerPayoutWallet',
});
```

## Approve Permit2

For ERC-20 input tokens, the user may need a one-time approval from each token to Permit2 before the Permit2 signature can be spent by the V5 contract.

```ts theme={"dark"}
await sweepr.evm.approvePermit2(walletClient, publicClient, {
  owner: userAddress,
  token: inputToken,
  amount: inputAmount,
});
```

You can check allowance first:

```ts theme={"dark"}
const allowance = await sweepr.evm.checkPermit2Allowance(publicClient, {
  owner: userAddress,
  token: inputToken,
  amount: inputAmount,
});
```

## Sign Permit2

Ask the user's wallet to sign the Permit2 typed data returned by `build.permit2`.

```ts theme={"dark"}
const permitSignature = await sweepr.evm.signPermit2(walletClient, build);
```

## Send Sweep Transaction

Use the SDK helper for the normal path. It verifies the fee authorization again before sending unless `skipVerification` is explicitly set.

```ts theme={"dark"}
const txHash = await sweepr.evm.sendSweep(walletClient, build, permitSignature);
```

If your wallet integration requires manual transaction construction, use the lower-level helper:

```ts theme={"dark"}
const tx = sweepr.evm.finalizeV2Transaction(build, permitSignature);
```

## Confirm With Sweepr

After the transaction is submitted, send the hash back to Sweepr. Sweepr reads the receipt and confirms the actual split from the `SweepExecutedV5` event.

```ts theme={"dark"}
await sweepr.sweep.confirm(build.sweepId, txHash);
```

Confirm is idempotent for the same submitted transaction hash. Sweepr rejects a different transaction hash after a sweep is already confirmed.

## Check Status

```ts theme={"dark"}
const status = await sweepr.sweep.status(build.sweepId);
```

Important status values:

* `pending`: transaction is not indexed yet or still waiting.
* `completed`: Sweepr matched the V5 event to the original fee authorization.
* `expired`: the fee authorization expired before a transaction was submitted.
* `failed`: the submitted transaction reverted or could not be accepted.

## V1 Solana

V2 on-chain partner fee split is EVM-only. Use `version: 'v1'` for Solana until the Sweepr Solana settlement program is live.
