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

# With Bun

> Accept Armory payments in Bun

Accept crypto payments in your Bun HTTP server with the Armory middleware.

## Installation

```bash theme={null}
# npm
npm install @armory-sh/middleware-bun

# yarn
yarn add @armory-sh/middleware-bun

# pnpm
pnpm add @armory-sh/middleware-bun

# bun
bun add @armory-sh/middleware-bun
```

## Quick Start

```typescript theme={null}
import { createBunMiddleware } from '@armory-sh/middleware-bun';

const middleware = createBunMiddleware({
  payTo: '0xYourWalletAddress...',
  amount: '1.0'
});

Bun.serve({
  port: 3000,
  fetch: async (req) => {
    const result = await middleware(req);

    // If middleware returns a response, payment failed/required
    if (result) return result;

    // Payment verified — handle your request
    return new Response(JSON.stringify({ data: 'protected content' }));
  }
});
```

***

## How It Works

The middleware returns:

* `null` if payment is valid (your handler proceeds)
* A `Response` object if payment is missing/invalid (returned to client)

***

## Settlement Modes

Control how payments are settled after verification:

```typescript theme={null}
const middleware = createBunMiddleware({
  payTo: '0x...',
  amount: '1.0',
  settlementMode: 'verify'  // | 'settle' | 'async'
});
```

| Mode     | Description                                   |
| -------- | --------------------------------------------- |
| `verify` | Verify only, don't settle (great for testing) |
| `settle` | Verify and settle on-chain before responding  |
| `async`  | Return immediately, settle in background      |

***

## Configuration

```typescript theme={null}
const middleware = createBunMiddleware({
  payTo: '0x...',
  amount: '1.0',
  settlementMode: 'verify'
});
```

## Route Configuration

For per-route behavior, use `createRouteAwareBunMiddleware`:

```typescript theme={null}
import { createRouteAwareBunMiddleware } from '@armory-sh/middleware-bun';

const middleware = createRouteAwareBunMiddleware({
  routes: ['/api/basic', '/api/premium/*'],
  payTo: '0xYourAddress...',
  amount: '$1.00',
  network: 'base',
  perRoute: {
    '/api/premium/*': {
      amount: '$5.00'
    }
  }
});
```

***

## Tips

<Tip>
  Use `settlementMode: 'verify'` during development to skip on-chain settlement while still testing payment verification.
</Tip>

<Note>
  The `amount` can be a human-readable string like `"1.0"` — no manual decimal calculation needed.
</Note>

<Warning>
  With `settlementMode: 'settle'`, responses will be delayed until the on-chain transaction completes. Use `async` for better UX.
</Warning>

***

## More Information

See [`@armory-sh/middleware-bun`](/packages/middleware-bun) for full configuration options.
