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

# Build Transaction

> Compile a trade quote into ready-to-sign transaction calldata.

Takes the route(s) you selected from `/v1/quotes` (via `protocol`) and returns transaction data ready to sign and submit.

### Body

<ParamField body="sender" type="string" required>Wallet address sending the transaction.</ParamField>

<ParamField body="refundee" type="string" required>Address to receive refunds.</ParamField>

<ParamField body="fromChain" type="integer" required>Source chain ID for every item in `data`.</ParamField>

<ParamField body="gasless" type="boolean" required>`false` for standard execution; `true` for the gasless/intent flow.</ParamField>

<ParamField body="data" type="object[]" required>
  Array of trade legs to build.

  <Expandable title="data item">
    <ParamField body="amount" type="string" required>Amount in the source token's smallest unit.</ParamField>

    <ParamField body="srcToken" type="string" required>Source token contract address.</ParamField>

    <ParamField body="srcDecimals" type="integer">Source token decimals.</ParamField>

    <ParamField body="destToken" type="string" required>Destination token contract address.</ParamField>

    <ParamField body="destDecimals" type="integer">Destination token decimals.</ParamField>

    <ParamField body="toChain" type="integer" required>Destination chain ID.</ParamField>

    <ParamField body="protocol" type="string" required>Provider ID selected from the quote response (e.g. `recommendedSource`).</ParamField>

    <ParamField body="recipient" type="string" required>Address to receive the destination tokens.</ParamField>

    <ParamField body="slippage" type="number" required>Slippage tolerance, in percent.</ParamField>

    <ParamField body="additionalInfo" type="object">Route-specific data echoed back from the quote.</ParamField>

    <ParamField body="permitData" type="string">Pre-signed permit data for the source token.</ParamField>
  </Expandable>
</ParamField>

<ParamField body="private" type="boolean">Request private/MEV-protected execution.</ParamField>

<ParamField body="disableEstimation" type="boolean">Skip gas estimation for a faster build.</ParamField>

<ParamField body="hasPermit2ApprovalForAllTokens" type="boolean">Set `true` if Permit2 approval already exists for every token in `data`.</ParamField>

<ParamField body="publicKey" type="string">Required for Bitcoin-chain transactions only.</ParamField>

### Response - non-gasless (`gasless: false`)

<ResponseField name="status" type="string">`"success"` when the build succeeds.</ResponseField>

<ResponseField name="txId" type="string">Unique build/transaction ID - use for status polling and broadcasting.</ResponseField>

<ResponseField name="chainId" type="integer">Chain where the transaction is to be executed.</ResponseField>

<ResponseField name="transaction" type="object">
  Chain-specific payload - shape depends on the chain type.

  <Expandable title="transaction (evm)">
    <ResponseField name="from" type="string" />

    <ResponseField name="data" type="string">Hex-encoded calldata.</ResponseField>
    <ResponseField name="to" type="string">Contract to call.</ResponseField>
    <ResponseField name="value" type="string">Native value to send, in wei.</ResponseField>

    <ResponseField name="gasLimit" type="string" />
  </Expandable>

  <Expandable title="transaction (svm - Solana)">
    <ResponseField name="from" type="string" />

    <ResponseField name="data" type="string" />

    <ResponseField name="blockhash" type="string" />

    <ResponseField name="lastValidBlockHeight" type="integer" />
  </Expandable>

  <Expandable title="transaction (btc - Bitcoin)">
    <ResponseField name="from" type="string" />

    <ResponseField name="data" type="string" />

    <ResponseField name="inputs" type="object[]">PSBT inputs.</ResponseField>
    <ResponseField name="outputs" type="object[]">PSBT outputs.</ResponseField>

    <ResponseField name="feeRate" type="integer" />
  </Expandable>

  <Expandable title="transaction (btcln - Bitcoin Lightning)">
    <ResponseField name="paymentRequestType" type="string">`"bolt11"`</ResponseField>

    <ResponseField name="paymentRequest" type="string" />

    <ResponseField name="paymentExpiry" type="integer" />
  </Expandable>

  <Expandable title="transaction (HyperLiquid)">
    <ResponseField name="signTypedData" type="object[]">Array of `{ domain, types, primaryType, message }` typed-data payloads to sign.</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="gasless" type="boolean">`false`.</ResponseField>

<ResponseField name="private" type="boolean">Echoes whether private/MEV-protected execution was used.</ResponseField>

<ResponseField name="quotes" type="object">
  Per-pair summary keyed by pair ID.

  <Expandable title="quotes[pairId]">
    <ResponseField name="provider" type="string" />

    <ResponseField name="destAmount" type="string" />

    <ResponseField name="minDestAmount" type="string" />

    <ResponseField name="priceImpact" type="string" />

    <ResponseField name="duration" type="string" />

    <ResponseField name="additionalInfo" type="object">Provider-specific extra data (shape varies).</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="data" type="string">`@deprecated` - top-level mirror of `transaction.data` for EVM chains.</ResponseField>

<ResponseField name="from" type="string">`@deprecated` - top-level mirror of `transaction.from`.</ResponseField>

<ResponseField name="to" type="string">`@deprecated` - top-level mirror of `transaction.to`.</ResponseField>

<ResponseField name="value" type="string">`@deprecated` - top-level mirror of `transaction.value`.</ResponseField>

<ResponseField name="gasLimit" type="string">`@deprecated` - top-level mirror of `transaction.gasLimit`.</ResponseField>

<ResponseField name="svmTxData" type="object">`{ blockhash, lastValidBlockHeight }`, present for Solana transactions.</ResponseField>

<ResponseField name="btcTxData" type="object">`{ inputs, outputs, feeRate }`, present for Bitcoin transactions.</ResponseField>

<ResponseField name="btclnTxData" type="object">`{ paymentRequestType: "bolt11", paymentRequest, paymentExpiry }`, present for Bitcoin Lightning.</ResponseField>

<ResponseField name="additionalInfo" type="object">`Record<string, Record<string, unknown>>`.</ResponseField>

<ResponseField name="updatedQuotes" type="object">`Record<string, string>` - refreshed destination amounts keyed by pair ID.</ResponseField>

### Response - gasless (`gasless: true`)

<ResponseField name="status" type="string">`"success"`.</ResponseField>

<ResponseField name="txId" type="string">Intent ID - pass to `/v1/gasless/executeTx` once signed.</ResponseField>

<ResponseField name="transaction" type="object">
  Typed-data payload to sign.

  <Expandable title="transaction (bridge)">
    <ResponseField name="executorFeesHash" type="string" />

    <ResponseField name="swapDataHash" type="string">Absent for pure EIP-2612/bridge-only intents.</ResponseField>

    <ResponseField name="adapterDataHash" type="string" />

    <ResponseField name="txType" type="string">`"bridge"`</ResponseField>

    <ResponseField name="value" type="string" />
  </Expandable>

  <Expandable title="transaction (swap)">
    <ResponseField name="executorFeesHash" type="string" />

    <ResponseField name="swapDataHash" type="string" />

    <ResponseField name="txType" type="string">`"swap"`</ResponseField>

    <ResponseField name="value" type="string" />
  </Expandable>
</ResponseField>

<ResponseField name="quotes" type="object">Same shape as the non-gasless response above.</ResponseField>

<ResponseField name="gasless" type="boolean">`true`.</ResponseField>

<ResponseField name="onlySwapData" type="boolean">`false`.</ResponseField>

### Examples

<RequestExample>
  ```bash curl theme={null}
  curl -X POST https://api.dzap.io/v1/buildTx \
    -H "Content-Type: application/json" \
    -d '{
      "sender": "0x99BCEBf44433E901597D9fCb16E799a4847519f6",
      "refundee": "0x99BCEBf44433E901597D9fCb16E799a4847519f6",
      "fromChain": 42161,
      "gasless": false,
      "data": [
        {
          "amount": "1000000",
          "srcToken": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
          "destToken": "0x4200000000000000000000000000000000000006",
          "toChain": 8453,
          "protocol": "across",
          "recipient": "0x99BCEBf44433E901597D9fCb16E799a4847519f6",
          "slippage": 1
        }
      ]
    }'
  ```

  ```ts SDK theme={null}
  const request = {
    sender: userAccount,
    refundee: userAccount,
    fromChain: 42161,
    gasless: false,
    data: [
      {
        amount: '1000000',
        srcToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
        destToken: '0x4200000000000000000000000000000000000006',
        toChain: 8453,
        protocol: 'across',
        recipient: userAccount,
        slippage: 1,
      },
    ],
  };

  // Build only:
  const buildResponse = await dzap.buildTradeTxn(request);

  // Or build + sign + execute in one call:
  const result = await dzap.trade({ request, signer });
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "status": "success",
    "txId": "0xabc123...",
    "chainId": 42161,
    "transaction": {
      "from": "0x99BCEBf44433E901597D9fCb16E799a4847519f6",
      "data": "0x...",
      "to": "0x1d46863e3592745008b5CbbAC12014F67329A9b8",
      "value": "0",
      "gasLimit": "350000"
    },
    "gasless": false,
    "private": false,
    "quotes": {
      "across": {
        "provider": "across",
        "destAmount": "300000000000000",
        "minDestAmount": "298500000000000",
        "duration": "90"
      }
    },
    "additionalInfo": {},
    "updatedQuotes": {}
  }
  ```
</ResponseExample>

<Note>
  Use the `txId` to poll `/v1/status` once the transaction has been signed and sent.
</Note>
