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

# Delta API TypeScript example

> End-to-end TypeScript example: call the Velora Delta API to quote a gasless 1 ETH → USDC intent via plain fetch.

A minimal Node script that calls `GET /v2/quote?mode=DELTA` and prints the recommended route's expected output and the `spender` from the returned `delta` block. No SDK, just `fetch`.

## File tree

```text theme={null}
my-app/
├─ package.json
├─ tsconfig.json
└─ src/
   └─ quote.ts
```

## Install

<CodeGroup>
  ```bash pnpm theme={null}
  mkdir my-app && cd my-app
  pnpm init
  pnpm add -D typescript tsx @types/node
  pnpm tsc --init
  ```

  ```bash npm theme={null}
  mkdir my-app && cd my-app
  npm init -y
  npm install -D typescript tsx @types/node
  npx tsc --init
  ```

  ```bash yarn theme={null}
  mkdir my-app && cd my-app
  yarn init -y
  yarn add -D typescript tsx @types/node
  yarn tsc --init
  ```
</CodeGroup>

## `src/quote.ts`

```ts theme={null}
const params = new URLSearchParams({
  srcToken:     '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // ETH
  destToken:    '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC
  amount:       '1000000000000000000', // 1 ETH
  srcDecimals:  '18',
  destDecimals: '6',
  side:         'SELL',
  chainId:      '1',
  mode:         'DELTA',
  userAddress:  '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
  partner:      'my-app-name',
});

const res = await fetch(`https://api.velora.xyz/v2/quote?${params}`);

if (!res.ok) {
  throw new Error(`HTTP ${res.status}: ${await res.text()}`);
}

const { delta } = await res.json();

console.log('expected output:', delta.route.origin.output.amount);
console.log('spender:        ', delta.spender);
```

## Run it

```bash theme={null}
pnpm tsx src/quote.ts
```

You should see the recommended route's expected output (USDC, 6 decimals) and the `spender` address to approve before building the order.

## Recommended route vs alternatives

The `delta` block carries a single recommended `route`. For crosschain swaps it also returns `alternatives`: other bridge routes you can offer the user. Pass whichever `route` you choose, unmodified, into the build step.

```ts theme={null}
const { delta } = await (await fetch(`https://api.velora.xyz/v2/quote?${params}`)).json();

const route  = delta.route;                // recommended route
const others = delta.alternatives;         // crosschain only
```

## Next: build, sign, submit

Pass the unmodified `delta.route` into `POST /v2/delta/orders/build` (with `owner` set to the user address) to get EIP-712 typed data back as `{ toSign, orderHash }`. Sign `toSign` with an ERC-2098 compact signature, then `POST /v2/delta/orders` with `order` (the `toSign.value`), the `signature`, `chainId`, and your `partner`. Poll `GET /v2/delta/orders/{orderId}` for status. See [Delta → How it works](/delta/how-it-works).

<Warning>
  Pass `delta.route` **verbatim** to `/v2/delta/orders/build`. Reordering or re-encoding it will cause the build call to reject.
</Warning>

## Related pages

* [Delta overview](/delta/overview) — when to use Delta intents.
* [Delta → How it works](/delta/how-it-works) — quote → build → sign → auction → settle.
* [Delta API reference](/api-reference/delta/overview) — full parameter list.
* [SDK](/sdk/overview) — typed TypeScript wrapper if you'd rather not handle HTTP yourself.
