# Quickstart

> Get a quote from the hosted LayerHop API, build the transaction, sign it with viem or a Solana wallet, report it and track the order to completion.

Source: https://docs.layerhop.com/quickstart

To make your first LayerHop swap, call `GET https://api.layerhop.com/v1/quote`, build the winning quote with `POST /v1/orders`, have the user's wallet sign and send it, report the hash with `POST /v1/orders/{quoteId}/submitted`, then track the order. The steps below do this with the TypeScript SDK; every step maps to one REST call in the [API reference](/api-reference).

## 1. Check the API

The public API is hosted at `https://api.layerhop.com/v1`. No account is needed to try it:

```bash
curl https://api.layerhop.com/v1/health
# {"ok":true,"providers":["jupiter","relay","debridge","zerox","kyberswap","lifi","across", …]}
```

`providers` lists the providers loaded on that deployment.

Prefer clicking to typing? Send these requests from the [API playground](/playground), or import the [Postman collection](/layerhop.postman_collection.json) (Postman **Import → Link**: `https://docs.layerhop.com/layerhop.postman_collection.json`; Insomnia and Bruno import it too). The raw spec is at [/openapi.yaml](/openapi.yaml).

```bash
curl "https://api.layerhop.com/v1/quote?srcChain=base&srcToken=USDC&amount=100000000&dstChain=solana&dstToken=SOL&sender=0x1111111111111111111111111111111111111111&recipient=9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
```

## 2. Get an API key (optional)

Requests without a key are limited per IP (60 per minute by default). For production, sign in to the [dashboard](https://dashboard.layerhop.com) with an EVM or Solana wallet and create a key. Keys look like `lh_live_…` and go in the `x-api-key` header. Keyed requests get their own rate limit, show up in your usage and logs, and their orders can trigger your [webhooks](/guides/webhooks). See [Dashboard & API keys](/guides/dashboard-and-api-keys).

## 3. Install the SDK

`@layerhop/sdk` has no runtime dependencies and works in Node, browsers and edge runtimes.

```bash
npm install @layerhop/sdk
```

```ts
import { LayerHop } from "@layerhop/sdk";

export const lh = new LayerHop({
  apiKey: process.env.LAYERHOP_API_KEY, // optional, sent as x-api-key
  channel: "api",                       // fee channel, see Fees & channels
  // baseUrl defaults to https://api.layerhop.com
});
```

## 4. Get a quote

Amounts are **integer strings in base units**. 100 USDC (6 decimals) is `"100000000"`.

```ts
const { best, quotes, errors } = await lh.quote({
  srcChain: "base",
  srcToken: "USDC",
  amount: "100000000",
  dstChain: "solana",
  dstToken: "SOL",
  sender: "0x1111111111111111111111111111111111111111",      // pays on Base
  recipient: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM", // receives on Solana
  slippageBps: 50,
});

console.log(best.provider, best.dstAmount, best.dstAmountMin, best.estimatedSeconds);
console.log(`LayerHop fee: ${best.fees.ourFeeBps} bps`);
```

`best` is `quotes[0]`. `errors` lists providers that could not quote; they do not fail the request. Each quote expires at `expiresAt` (unix seconds), 30 to 60 seconds after it was made depending on the provider.

## 5. Build the transaction

```ts
const tx = await lh.buildTx(best.quoteId);
```

`tx` is a `BuiltTx`: either `{ vm: "evm", chainId, to, data, value, approval? }` or `{ vm: "svm", serializedTx, submitViaApi? }`. Build it right after the user confirms; some providers expect the transaction on chain within about 30 seconds.

To check that it would succeed before asking for a signature, call `await lh.simulate(best.quoteId)`. See [Simulation](/concepts/simulation).

## 6. Sign and send on EVM

If `tx.approval` is present, the user first approves the spender for the input token. Then send the main transaction.

```ts
import { createWalletClient, createPublicClient, custom, http, erc20Abi } from "viem";
import { base } from "viem/chains";

const wallet = createWalletClient({ chain: base, transport: custom(window.ethereum!) });
const pub = createPublicClient({ chain: base, transport: http() });
const [account] = await wallet.requestAddresses();

let srcTxHash = "";
if (tx.vm === "evm") {
  if (tx.approval) {
    const { token, spender, amount } = tx.approval;
    const allowance = await pub.readContract({
      address: token as `0x${string}`, abi: erc20Abi, functionName: "allowance",
      args: [account!, spender as `0x${string}`],
    });
    if (allowance < BigInt(amount)) {
      const approveHash = await wallet.writeContract({
        account: account!, address: token as `0x${string}`, abi: erc20Abi,
        functionName: "approve", args: [spender as `0x${string}`, BigInt(amount)],
      });
      await pub.waitForTransactionReceipt({ hash: approveHash });
    }
  }
  srcTxHash = await wallet.sendTransaction({
    account: account!,
    to: tx.to as `0x${string}`,
    data: tx.data as `0x${string}`,
    value: BigInt(tx.value),
  });
}
```

The wallet must be on `tx.chainId`; switch first if needed (`wallet.switchChain({ id: tx.chainId })`). See [Approvals](/concepts/approvals).

## 7. Sign and send on Solana

`serializedTx` is a base64 `VersionedTransaction`. Sign it with any wallet adapter. If `submitViaApi` is true, send the signed bytes back through LayerHop; otherwise broadcast them yourself.

```ts
import { Connection, VersionedTransaction } from "@solana/web3.js";

const connection = new Connection("https://api.mainnet-beta.solana.com");

if (tx.vm === "svm") {
  const unsigned = VersionedTransaction.deserialize(Buffer.from(tx.serializedTx, "base64"));
  const signed = await wallet.signTransaction(unsigned); // e.g. useWallet() from @solana/wallet-adapter-react
  const bytes = signed.serialize();

  srcTxHash = tx.submitViaApi
    ? await lh.submit(best.quoteId, Buffer.from(bytes).toString("base64"))
    : await connection.sendRawTransaction(bytes, { skipPreflight: false, maxRetries: 3 });
}
```

In the browser, use a base64 helper instead of `Buffer` if your bundler does not polyfill it. See [The submitViaApi flow](/concepts/submit-via-api).

## 8. Report the transaction

After the wallet broadcasts, tell LayerHop which transaction belongs to the quote:

```ts
await lh.reportSubmitted(best.quoteId, srcTxHash); // POST /v1/orders/{quoteId}/submitted
```

This moves the order from `built` to `submitted`, starts server-side tracking, and lets `order.*` [webhooks](/guides/webhooks) fire. It is idempotent. `lh.submit()` already does this for `submitViaApi` transactions, so calling it again is harmless.

## 9. Track the order

`watch()` polls `GET /v1/orders/{provider}/{id}` every 3 seconds and yields each state change until the order is final.

```ts
for await (const status of lh.watch(best.provider, srcTxHash)) {
  console.log(status.state, status.dstTxHash ?? "");
  // pending → filled (or refunded / failed)
}
```

For cross-chain providers (`relay`, `debridge`, `lifi`) pass the **source transaction hash**. Same-chain providers (`jupiter`, `zerox`, `kyberswap`) report `unknown` from this endpoint; confirm the transaction on chain, use [`GET /v1/orders`](/api-reference#list-orders-by-address), or subscribe to webhooks. See [Order tracking](/concepts/order-tracking).

## Can I develop without real funds?

Yes, two ways. The providers LayerHop aggregates are mainnet-only, so neither uses a testnet:

- **Test mode:** create an `lh_test_` key in the dashboard and use the hosted API as usual. Quotes come from the sandbox provider, transactions are placeholders and orders fill in about 10 seconds. See [Test mode](/guides/test-mode).
- **Offline:** `npx @layerhop/cli dev` starts a local mock API on `http://127.0.0.1:8787` with the same deterministic outcomes, signed webhooks and no account. Pass `baseUrl: "http://127.0.0.1:8787"` to the SDK (or set `LAYERHOP_API_URL`). In CI, the setup-layerhop GitHub Action starts it for you. See [Local development](/guides/local-development).

**Never broadcast a test or mock transaction**; they are placeholders sent to `0x…dEaD`.

## Next steps

- [EVM → Solana guide](/guides/evm-to-solana) and [Solana → EVM guide](/guides/solana-to-evm): the full flows with error handling.
- [Error handling & retries](/guides/error-handling): what to do with `QUOTE_EXPIRED`, `NO_ROUTE` and the rest.
- [Starter templates](/guides/examples): a Next.js swap page, checkout, a deposit address backend, the widget and an AI agent, ready to deploy.
- [SDK reference](/sdk) and [API reference](/api-reference).
