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

# TypeScript SDK

> A typed client for every endpoint. No runtime dependencies.

```bash theme={null}
npm install @kernlog/bridg-sdk
```

Source and releases: [github.com/Kernlog/bridg-sdk](https://github.com/Kernlog/bridg-sdk). Node 18+ or any runtime with a global `fetch`. One method per endpoint, typed from the API's OpenAPI document, no runtime dependencies.

## Quote, build, sign, submit, track

```ts theme={null}
import { createClient } from '@kernlog/bridg-sdk';

const bridg = createClient();

// Markets
const { routes } = await bridg.getRoutes({ fromChain: 'base', toChain: 'solana' });

// Quote: 100 USDC on Base to USDC on Solana
const quote = await bridg.getQuote({
  fromChain: 'base',
  toChain: 'solana',
  fromToken: 'USDC',
  toToken: 'USDC',
  amountAtomic: '100000000',
  sender: '0xYourEvmWallet',
  recipient: 'YourSolanaWallet',
});
quote.best; // the row Bridg builds by default
quote.bestByTime; // quoteId of the fastest executable row
quote.quotes; // every venue that answered, best first

// Build the unsigned steps. Pass quoteId to build another row.
const build = await bridg.buildTransfer({ decisionId: quote.decisionId });

// Sign build.steps in order with your user's wallet, then report the hash
await bridg.submitTransfer(build.transferId, { txHash: '0x…', step: 'main' });

// Track until terminal
const transfer = await bridg.waitForTransfer(build.transferId, {
  onUpdate: (t) => console.log(t.status),
});
```

## Configuration

```ts theme={null}
createClient({
  baseUrl: 'https://api.bridg.now/v1', // default
  headers: { 'x-integrator': 'my-app' },
  fetch: customFetch,
});
```

## Errors

Every API error is a `BridgError` carrying the API's `code`, the HTTP `status`, `details` and, on `429`, `retryAfterMs`. Codes are listed on [Errors](/reference/errors).

```ts theme={null}
import { isBridgError } from '@kernlog/bridg-sdk';

try {
  await bridg.buildTransfer({ decisionId });
} catch (error) {
  if (isBridgError(error) && error.code === 'quote_drifted') {
    // re-quote and choose again
  }
}
```

## Methods

| Method                                                              | Endpoint                                                            |
| ------------------------------------------------------------------- | ------------------------------------------------------------------- |
| `getSourceChains()`                                                 | [`GET /bridge/source-chains`](/api-reference/markets/source-chains) |
| `getRoutes({ fromChain, toChain, privacy? })`                       | [`GET /bridge/routes`](/api-reference/markets/routes)               |
| `getVenues()`                                                       | [`GET /bridge/venues`](/api-reference/markets/venues)               |
| `getQuote(request)`                                                 | [`POST /bridge/quote`](/api-reference/quote/quote)                  |
| `buildTransfer({ decisionId, quoteId? })`                           | [`POST /bridge/build`](/api-reference/quote/build)                  |
| `submitTransfer(transferId, { txHash \| signedTransaction, step })` | [`POST /bridge/transfers/{id}/submit`](/api-reference/quote/submit) |
| `getTransfer(transferId)`                                           | [`GET /bridge/transfers/{id}`](/api-reference/quote/transfer)       |
| `waitForTransfer(transferId, options?)`                             | polls the transfer until it is terminal                             |

Every request and response type is exported: `import type { QuoteResponse, BuildStep, Transfer } from '@kernlog/bridg-sdk'`.
