# The submitViaApi flow

> Why some Solana transactions must be signed by the wallet but submitted through POST /v1/orders/submit, and how to do it.

Source: https://docs.layerhop.com/concepts/submit-via-api

When a Solana transaction from LayerHop has `submitViaApi: true`, the user's wallet must **only sign** it, and you send the signed bytes to `POST /v1/orders/submit` instead of an RPC node. LayerHop forwards them to the provider, records the order as submitted, and returns the transaction signature.

## What does submitViaApi mean?

```json
{ "vm": "svm", "serializedTx": "AQAAAA…", "submitViaApi": true }
```

| `submitViaApi` | What you do after signing |
|---|---|
| absent or `false` | Broadcast the signed transaction yourself (`sendRawTransaction`), then [report it](/api-reference#report-the-broadcast-transaction) |
| `true` | Send it to `POST /v1/orders/submit`; do not broadcast it |

## Which transactions use it?

Jupiter transactions built through Jupiter's order-and-execute path. Those routes can be RFQ quotes (a market maker co-signs) or gasless swaps (Jupiter pays the fee and co-signs), which only become valid when Jupiter adds its signature, so a plain RPC broadcast would not land them.

Most Jupiter quotes on LayerHop use Jupiter's `/build` path instead: LayerHop compiles a regular v0 transaction that the wallet broadcasts itself, without `submitViaApi`. The order-and-execute path is the fallback when no LayerHop fee account fits the token pair. Always read the flag rather than assuming by provider.

## How do I submit through the API?

1. `POST /v1/orders` → `{ vm: "svm", serializedTx, submitViaApi: true }`.
2. Deserialize, sign with the user's wallet, serialize, base64-encode.
3. `POST /v1/orders/submit` with `{ quoteId, signedTransaction }`.
4. The response is `{ provider, txHash }`, where `txHash` is the Solana signature. The order is marked `submitted` for you, so no separate report is needed.

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

const tx = await lh.buildTx(quote.quoteId);
if (tx.vm === "svm") {
  const signed = await wallet.signTransaction(VersionedTransaction.deserialize(Buffer.from(tx.serializedTx, "base64")));
  const b64 = Buffer.from(signed.serialize()).toString("base64");
  const signature = tx.submitViaApi
    ? await lh.submit(quote.quoteId, b64)                       // through LayerHop
    : await connection.sendRawTransaction(signed.serialize());  // straight to the network
  if (!tx.submitViaApi) await lh.reportSubmitted(quote.quoteId, signature);
}
```

## What are the rules?

- Calling submit for a quote whose transaction the wallet broadcasts returns [`INVALID_PARAMS`](/errors/INVALID_PARAMS).
- Submit within seconds. If the provider rejects the transaction (price moved, quote stale) you get [`PROVIDER_ERROR`](/errors/PROVIDER_ERROR); get a new quote and sign again.
- LayerHop only relays the bytes your user signed. It cannot change them, and it never sees a private key.
