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

# Omnibus Sweep (Node.js)

> Create customer wallets, mint USDC gaslessly, and sweep balances to an omnibus account using Dynamic's Node SDK and Pimlico on Base Sepolia

## Overview

This demo uses Dynamic server wallets and sponsored transactions to create and manage many customer wallets, then sweep their balances into a central omnibus account:

* Programmatically create wallets (including the omnibus) with 2-of-2 threshold signatures for strong control
* Use a 7702 smart account and Pimlico paymaster to sponsor gas on Base Sepolia (no ETH needed)
* Mint random demo USDC amounts (up to 1000) to each customer wallet, then transfer all balances to the omnibus account

## Prerequisites

* Node.js 18+
* Dynamic API token and Environment ID
* Pimlico API key (for gasless on Base Sepolia)
* Cloned example repository: [github.com/dynamic-labs/examples/nodejs-omnibus-sweep](https://github.com/dynamic-labs/examples/tree/main/examples/nodejs-omnibus-sweep)
* Embedded wallets enabled in your Dynamic developer console
* "Allow multiple embedded wallets per chain" toggled on in Embedded Wallets settings

> [!NOTE]
>
> Find your API tokens and Environment ID in the [Dynamic Developer Console](https://console.dynamic.xyz/dashboard/developer/api).

## Setup

Copy the `.example.env` file to `.env` and fill in your credentials:

```bash theme={"system"}
cp .example.env .env
```

```env .env theme={"system"}
DYNAMIC_API_TOKEN=your_dynamic_api_token
DYNAMIC_ENVIRONMENT_ID=your_environment_id
PIMLICO_API_KEY=your_pimlico_api_key
# Optional chain override used by the code if provided:
# PIMLICO_BUNDLER_URL_84532=https://api.pimlico.io/v2/84532/rpc?apikey=your_pimlico_api_key
```

Install dependencies:

```bash npm theme={"system"}
npm install
```

```bash yarn theme={"system"}
yarn install
```

```bash pnpm theme={"system"}
pnpm install
```

```bash bun theme={"system"}
bun install
```

## How It Works

### Phases

1. Wallet creation (customers + one omnibus)
2. Funding customers with USDC (gasless mint)
3. Sweeping all customer balances to the omnibus account

### Demo Configuration

* Default wallets: 5 (override with a numeric CLI argument)
* Funding amount: random whole-dollar USDC per wallet from 1 to 1000
* USDC decimals: 6; sweeping converts dollars to token units before transfer
* Confirmations: waits for 2 transaction confirmations
* Concurrency: wallet creation is sequential; transactions run up to 10 in parallel
* Chain: Base Sepolia (chainId 84532)
* Token: demo USDC address from `constants.ts`

Wallet creation runs sequentially; transactions run concurrently (up to 10 at a time) to respect API limits while maintaining speed.

### Components

* **Wallet creation**: Uses Dynamic's server wallet client to create EVM wallets with 2-of-2 threshold signatures (TSS). (src/libs/dynamic.ts)
* **LocalAccount adapter**: Bridges Dynamic signing methods into a `viem` `LocalAccount` so it can be used with a smart account client. (src/libs/viem.ts)
* **Smart Account + Paymaster**: Builds a 7702-style smart account and submits sponsored transactions via Pimlico (EntryPoint v0.7). (src/libs/pimlico.ts)
* **Orchestration**: Coordinates create → fund → sweep → report. (src/omnibus-sweep.ts)
* **Explorer + utilities**: Formatting, explorers, unit conversion. (src/utils.ts)
* **Configuration**: Env reads, token ABI, contract addresses. (constants.ts)

### Configuration and Environment

* The `.env` variables defined in Setup are read by `constants.ts` and used across the libs.
  When a per-chain override is not set, the default Pimlico URL is derived from `PIMLICO_API_KEY`.

### Security Model

* Wallets are created with `ThresholdSignatureScheme.TWO_OF_TWO` and `backUpToClientShareService: false`.
* Transactions are signed via Dynamic's server-side signing methods and executed through a smart account.
* For fresh addresses with no code deployed, the script signs an authorization targeting the configured account implementation and includes it with the first transaction.
* Entry point: v0.7; smart account is created via `permissionless` 7702 helpers.

## Run the Demo

Default run (creates 5 wallets):

```bash pnpm theme={"system"}
pnpm omnibus
```

```bash npm theme={"system"}
npm run omnibus
```

```bash yarn theme={"system"}
yarn omnibus
```

```bash bun theme={"system"}
bunx tsx src/omnibus-sweep.ts
```

Custom number of wallets (example: 10):

```bash pnpm theme={"system"}
pnpm omnibus 10
```

```bash npm theme={"system"}
npm run omnibus -- 10
```

```bash yarn theme={"system"}
yarn omnibus 10
```

```bash theme={"system"}
npx tsx src/omnibus-sweep.ts 10
```

You'll see logs for wallet creation, USDC mints, and sweep transfers, ending with the omnibus address and totals transferred.

### Sample Output

Here's what you'll see when running the demo with 10 wallets:

```text theme={"system"}
Dynamic Gasless Transaction Demo - Omnibus Sweep
============================================================
Configuration: 10 wallets, funding random USDC amounts up to 1000
============================================================

Creating omnibus wallet for fund aggregation...
Omnibus wallet created: 0xbBdf18...c10B74

Creating 10 customer wallets...
Customer wallet 1 created: 0x7E3629...5A02f0
[... additional wallet creation logs ...]

Funding 10 customer wallets with USDC tokens...
Funded customer wallet 1 (0x7E3629...5A02f0): 33 USDC
[... additional funding transaction logs ...]

Sweeping funds from 10 customer wallets to omnibus account...
Swept customer wallet 1 (0x7E3629...5A02f0): 33 USDC to omnibus
[... additional sweep transaction logs ...]

============================================================
Demo completed successfully.
Total USDC transferred: 333 USDC
Omnibus wallet address: 0xbBdf18...c10B74
```

## Troubleshooting

* **401/403 during wallet creation**: Check `DYNAMIC_API_TOKEN` and `DYNAMIC_ENVIRONMENT_ID`.
* **Multiple wallets per chain not allowed**: Check "Allow multiple embedded wallets per chain" in Embedded Wallets settings.
* **Paymaster/bundler errors**: Verify `PIMLICO_API_KEY` or set `PIMLICO_BUNDLER_URL_84532`.
* **Insufficient confirmations**: The script waits for 2 confirmations per transaction; on congested testnets, this may take time.

### Additional Resources

* [Dynamic Node SDK Quickstart](https://www.dynamic.xyz/docs/node/quickstart.md)
* [Dynamic API Reference](https://www.dynamic.xyz/docs/api-reference/overview.md)
* [Transaction Sponsorship (Pimlico)](https://docs.pimlico.io/)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.