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

# Get swap status

> Poll the status of a swap by its swap_request_id. Covers same-chain and cross-chain swaps.

export const EndpointPath = ({type, path}) => {
  return <div class="flex w-full flex-col bg-background-light dark:bg-background-dark border-standard rounded-2xl p-1.5">
      <div class="flex items-center space-x-1.5">
        <div class="relative flex-1 flex gap-2 min-w-0 rounded-xl items-center cursor-pointer p-1.5 border-standard">
          <div class="rounded-lg font-bold px-1.5 py-0.5 text-sm leading-5 bg-blue-400/20 dark:bg-blue-400/20 text-blue-700 dark:text-blue-400">
            POST
          </div>
          <div class="flex items-center space-x-2 overflow-x-auto flex-1 no-scrollbar">
            <div class="group flex items-center flex-1 gap-0.5 font-mono">
              <div class="absolute right-0 p-2 bg-background-light dark:bg-background-dark rounded-lg hidden group-hover:block">
                <svg class="w-4 h-4 bg-gray-400 dark:bg-white/30"></svg>
              </div>
              <div class="text-sm text-gray-400">/</div>
              <div class="text-sm font-medium text-gray-800 dark:text-white min-w-max">
                public
              </div>
              <div class="text-sm text-gray-400">/</div>
              <div class="text-sm font-medium text-gray-800 dark:text-white min-w-max">
                v1
              </div>
              <div class="text-sm text-gray-400">/</div>
              <div class="text-sm font-medium text-gray-800 dark:text-white min-w-max">
                {type}
              </div>
              <div class="text-sm text-gray-400">/</div>
              <div class="text-sm font-medium text-gray-800 dark:text-white min-w-max">
                {path}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>;
};

export const NestedParam = ({parentKey, childKey, type, required, description, children}) => {
  const fullKey = `${parentKey}.${childKey}`;
  const anchorId = `body-${fullKey.replace(/\./g, '-')}`;
  return <div className="py-6 border-gray-100 dark:border-gray-800 border-b last:border-b-0">
  <div className="flex font-mono text-sm group/param-head param-head break-all relative" id={anchorId}>
    <div className="flex-1 flex content-start py-0.5 mr-5">
      <div className="flex items-center flex-wrap gap-2">
        <div className="absolute -top-1.5">
          <a href={`#${anchorId}`} className="-ml-[2.1rem] flex items-center opacity-0 border-0 group-hover/param-head:opacity-100 py-2 [.expandable-content_&]:-ml-[2.1rem]" aria-label="Navigate to header">
            <div className="w-6 h-6 text-gray-400 rounded-md flex items-center justify-center zinc-box bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20">
              <svg xmlns="http://www.w3.org/2000/svg" fill="gray" height="12px" viewBox="0 0 576 512">
                <path d="M0 256C0 167.6 71.6 96 160 96h72c13.3 0 24 10.7 24 24s-10.7 24-24 24H160C98.1 144 48 194.1 48 256s50.1 112 112 112h72c13.3 0 24 10.7 24 24s-10.7 24-24 24H160C71.6 416 0 344.4 0 256zm576 0c0 88.4-71.6 160-160 160H344c-13.3 0-24-10.7-24-24s10.7-24 24-24h72c61.9 0 112-50.1 112-112s-50.1-112-112-112H344c-13.3 0-24-10.7-24-24s10.7-24 24-24h72c88.4 0 160 71.6 160 160zM184 232H392c13.3 0 24 10.7 24 24s-10.7 24-24 24H184c-13.3 0-24-10.7-24-24s10.7-24 24-24z"></path>
              </svg>
            </div>
          </a>
        </div>
        <div className="font-semibold text-primary dark:text-primary-light cursor-pointer overflow-wrap-anywhere">
          <span className="text-gray-500 dark:text-gray-400">{parentKey}.</span>
          {childKey}
        </div>
        <div className="inline items-center gap-2 text-xs font-medium [&_div]:inline [&_div]:mr-2 [&_div]:leading-5">
          <div className="flex items-center px-2 py-0.5 rounded-md bg-gray-100/50 dark:bg-white/5 text-gray-600 dark:text-gray-200 font-medium break-all">
            <span>{type}</span>
          </div>
          {required && <span className="px-2 py-0.5 rounded-md bg-red-100/50 dark:bg-red-400/10 text-red-600 dark:text-red-300 font-medium whitespace-nowrap">
              required
            </span>}
        </div>
      </div>
    </div>
  </div>
  {children && <div className="mt-4">
      <div className="prose prose-sm prose-gray dark:prose-invert">
        {children}
      </div>
    </div>}
</div>;
};

export const H3Bordered = ({text}) => <h3 id={text.toLowerCase()} className="border-b pb-2.5 border-gray-100 dark:border-gray-800">
    {text}
  </h3>;

export const Authorizations = () => {
  return <div>
      <H3Bordered text="Authorizations" />

      <Tabs>
        <Tab title="API Key">
          <div className="flex text-sm group/param-head param-head break-all relative" id="authorization-x-stamp">
            <ParamField header="X-Stamp" type="string" required={true}>
              Cryptographically signed (stamped) request to be passed in as a header. For more info, see <a href="https://docs.turnkey.com/developer-reference/api-overview/stamps">here</a>.
            </ParamField>
          </div>
        </Tab>

        <Tab title="WebAuthn (Passkey)">
         <div className="flex text-sm group/param-head param-head break-all relative" id="authorization-x-stamp-webauthn">
            <ParamField body="X-Stamp-WebAuthn" type="string" required={true}>
              Cryptographically signed (stamped) request to be passed in as a header. For more info, see <a href="https://docs.turnkey.com/developer-reference/api-overview/stamps">here</a>.
            </ParamField>
          </div>
        </Tab>
      </Tabs>
    </div>;
};

<EndpointPath type="query" path="get_swap_status" />

<Authorizations />

<H3Bordered text="Body" />

<ParamField body="organizationId" type="string" required={true}>
  Unique identifier for a given Organization.
</ParamField>

<ParamField body="swapRequestId" type="string" required={true}>
  The swap\_request\_id returned by ExecuteSwap.
</ParamField>

<H3Bordered text="Response" />

A successful response returns the following fields:

<ResponseField name="status" type="string" required={true}>Normalized swap status. One of PENDING, COMPLETED, FAILED.</ResponseField>
<ResponseField name="swapKind" type="string" required={true}>SAME\_CHAIN or CROSS\_CHAIN.</ResponseField>
<ResponseField name="provider" type="string" required={true}>Swap provider that executed the swap.</ResponseField>
<ResponseField name="inputToken" type="string" required={true}>CAIP-19 asset ID for the input asset.</ResponseField>
<ResponseField name="outputToken" type="string" required={true}>CAIP-19 asset ID for the output asset.</ResponseField>
<ResponseField name="inputAmount" type="string" required={true}>Base-unit amount of the input asset.</ResponseField>
<ResponseField name="originTxHash" type="string" required={false}>Final included origin-chain transaction hash, when known.</ResponseField>

<ResponseField name="destinationTxHashes" type="array" required={false}>
  Provider-reported destination-chain transaction hashes; cross-chain COMPLETED only.

  <Expandable title="destinationTxHashes details">
    <NestedParam parentKey="destinationTxHashes" childKey="item" type="string" required={true}>
      item field
    </NestedParam>
  </Expandable>
</ResponseField>

<ResponseField name="outputAmount" type="string" required={false}>Actual base-unit output amount on COMPLETED, when known. Unset on FAILED.</ResponseField>

<ResponseField name="refund" type="object" required={false}>
  refund field

  <Expandable title="refund details">
    <NestedParam parentKey="refund" childKey="asset" type="string" required={true}>
      CAIP-19 asset returned to the user after a failed swap.
    </NestedParam>

    <NestedParam parentKey="refund" childKey="amount" type="string" required={true}>
      Base-unit amount of the refunded asset.
    </NestedParam>

    <NestedParam parentKey="refund" childKey="txHash" type="string" required={false}>
      Transaction that delivered the refunded funds, when applicable.
    </NestedParam>
  </Expandable>
</ResponseField>

<ResponseField name="updatedAt" type="string" required={true}>Timestamp of the last swap status change, as millisecond epoch string.</ResponseField>

<ResponseField name="error" type="object" required={false}>
  error field

  <Expandable title="error details">
    <NestedParam parentKey="error" childKey="reason" type="string" required={true}>
      Stable machine-readable failure reason. One of ORIGIN\_TRANSACTION\_FAILED or PROVIDER\_FILL\_FAILED.
    </NestedParam>

    <NestedParam parentKey="error" childKey="message" type="string" required={true}>
      Human-readable description of the swap failure.
    </NestedParam>

    <NestedParam parentKey="error" childKey="originTxError" type="object" required={false}>
      originTxError field

      <Expandable title="originTxError details">
        <NestedParam parentKey="error.originTxError" childKey="message" type="string" required={false}>
          Human-readable error message describing what went wrong.
        </NestedParam>

        <NestedParam parentKey="error.originTxError" childKey="revertChain" type="array" required={false}>
          Chain of revert errors from nested contract calls, ordered from outermost to innermost.

          <Expandable title="revertChain details">
            <NestedParam parentKey="error.originTxError.revertChain" childKey="address" type="string" required={false}>
              The contract address where the revert occurred.
            </NestedParam>

            <NestedParam parentKey="error.originTxError.revertChain" childKey="errorType" type="string" required={false}>
              Type of error: 'unknown', 'native', or 'custom'.
            </NestedParam>

            <NestedParam parentKey="error.originTxError.revertChain" childKey="displayMessage" type="string" required={false}>
              Human-readable message describing this revert.
            </NestedParam>

            <NestedParam parentKey="error.originTxError.revertChain" childKey="unknown" type="object" required={false}>
              unknown field

              <Expandable title="unknown details">
                <NestedParam parentKey="error.originTxError.revertChain.unknown" childKey="selector" type="string" required={false}>
                  The 4-byte error selector, if available.
                </NestedParam>

                <NestedParam parentKey="error.originTxError.revertChain.unknown" childKey="data" type="string" required={false}>
                  The raw error data, hex-encoded.
                </NestedParam>
              </Expandable>
            </NestedParam>

            <NestedParam parentKey="error.originTxError.revertChain" childKey="native" type="object" required={false}>
              native field

              <Expandable title="native details">
                <NestedParam parentKey="error.originTxError.revertChain.native" childKey="nativeType" type="string" required={false}>
                  The type of native error: 'error\_string', 'panic', or 'execution\_reverted'.
                </NestedParam>

                <NestedParam parentKey="error.originTxError.revertChain.native" childKey="message" type="string" required={false}>
                  The error message for Error(string) reverts.
                </NestedParam>

                <NestedParam parentKey="error.originTxError.revertChain.native" childKey="panicCode" type="string" required={false}>
                  The panic code for Panic(uint256) reverts.
                </NestedParam>
              </Expandable>
            </NestedParam>

            <NestedParam parentKey="error.originTxError.revertChain" childKey="custom" type="object" required={false}>
              custom field

              <Expandable title="custom details">
                <NestedParam parentKey="error.originTxError.revertChain.custom" childKey="errorName" type="string" required={false}>
                  The name of the custom error.
                </NestedParam>

                <NestedParam parentKey="error.originTxError.revertChain.custom" childKey="paramsJson" type="string" required={false}>
                  The decoded parameters as a JSON object.
                </NestedParam>
              </Expandable>
            </NestedParam>
          </Expandable>
        </NestedParam>

        <NestedParam parentKey="error.originTxError" childKey="solana" type="object" required={false}>
          solana field

          <Expandable title="solana details">
            <NestedParam parentKey="error.originTxError.solana" childKey="source" type="string" required={false}>
              Where the Solana failure occurred, such as simulation or preflight.
            </NestedParam>

            <NestedParam parentKey="error.originTxError.solana" childKey="rpcCode" type="number" required={false}>
              The Solana JSON-RPC error code, if available.
            </NestedParam>

            <NestedParam parentKey="error.originTxError.solana" childKey="rpcMessage" type="string" required={false}>
              The Solana JSON-RPC error message, if available.
            </NestedParam>

            <NestedParam parentKey="error.originTxError.solana" childKey="transactionErrorJson" type="string" required={false}>
              The raw Solana transaction error object serialized as JSON, if available.
            </NestedParam>

            <NestedParam parentKey="error.originTxError.solana" childKey="logs" type="array" required={false}>
              Program logs returned by Solana simulation or preflight, if available.

              <Expandable title="logs details">
                <NestedParam parentKey="error.originTxError.solana.logs" childKey="item" type="string" required={true}>
                  item field
                </NestedParam>
              </Expandable>
            </NestedParam>

            <NestedParam parentKey="error.originTxError.solana" childKey="unitsConsumed" type="string" required={false}>
              Compute units consumed during simulation or preflight, if available.
            </NestedParam>

            <NestedParam parentKey="error.originTxError.solana" childKey="innerInstructionsJson" type="string" required={false}>
              The raw Solana inner instructions payload serialized as JSON, if available.
            </NestedParam>
          </Expandable>
        </NestedParam>

        <NestedParam parentKey="error.originTxError" childKey="eth" type="object" required={false}>
          eth field

          <Expandable title="eth details">
            <NestedParam parentKey="error.originTxError.eth" childKey="revertChain" type="array" required={false}>
              Ethereum revert chain, ordered from outermost to innermost.

              <Expandable title="revertChain details">
                <NestedParam parentKey="error.originTxError.eth.revertChain" childKey="address" type="string" required={false}>
                  The contract address where the revert occurred.
                </NestedParam>

                <NestedParam parentKey="error.originTxError.eth.revertChain" childKey="errorType" type="string" required={false}>
                  Type of error: 'unknown', 'native', or 'custom'.
                </NestedParam>

                <NestedParam parentKey="error.originTxError.eth.revertChain" childKey="displayMessage" type="string" required={false}>
                  Human-readable message describing this revert.
                </NestedParam>

                <NestedParam parentKey="error.originTxError.eth.revertChain" childKey="unknown" type="object" required={false}>
                  unknown field

                  <Expandable title="unknown details">
                    <NestedParam parentKey="error.originTxError.eth.revertChain.unknown" childKey="selector" type="string" required={false}>
                      The 4-byte error selector, if available.
                    </NestedParam>

                    <NestedParam parentKey="error.originTxError.eth.revertChain.unknown" childKey="data" type="string" required={false}>
                      The raw error data, hex-encoded.
                    </NestedParam>
                  </Expandable>
                </NestedParam>

                <NestedParam parentKey="error.originTxError.eth.revertChain" childKey="native" type="object" required={false}>
                  native field

                  <Expandable title="native details">
                    <NestedParam parentKey="error.originTxError.eth.revertChain.native" childKey="nativeType" type="string" required={false}>
                      The type of native error: 'error\_string', 'panic', or 'execution\_reverted'.
                    </NestedParam>

                    <NestedParam parentKey="error.originTxError.eth.revertChain.native" childKey="message" type="string" required={false}>
                      The error message for Error(string) reverts.
                    </NestedParam>

                    <NestedParam parentKey="error.originTxError.eth.revertChain.native" childKey="panicCode" type="string" required={false}>
                      The panic code for Panic(uint256) reverts.
                    </NestedParam>
                  </Expandable>
                </NestedParam>

                <NestedParam parentKey="error.originTxError.eth.revertChain" childKey="custom" type="object" required={false}>
                  custom field

                  <Expandable title="custom details">
                    <NestedParam parentKey="error.originTxError.eth.revertChain.custom" childKey="errorName" type="string" required={false}>
                      The name of the custom error.
                    </NestedParam>

                    <NestedParam parentKey="error.originTxError.eth.revertChain.custom" childKey="paramsJson" type="string" required={false}>
                      The decoded parameters as a JSON object.
                    </NestedParam>
                  </Expandable>
                </NestedParam>
              </Expandable>
            </NestedParam>
          </Expandable>
        </NestedParam>
      </Expandable>
    </NestedParam>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash title="cURL" theme={"system"}
  curl --request POST \
    --url https://api.turnkey.com/public/v1/query/get_swap_status \
    --header 'Accept: application/json' \
    --header 'Content-Type: application/json' \
    --header "X-Stamp: <string> (see Authorizations)" \
    --data '{
      "organizationId": "<string>",
      "swapRequestId": "<string>"
  }'
  ```

  ```javascript title="JavaScript" theme={"system"}
  import { Turnkey } from "@turnkey/sdk-server";

  const turnkeyClient = new Turnkey({
    apiBaseUrl: "https://api.turnkey.com",
    apiPublicKey: process.env.API_PUBLIC_KEY!,
    apiPrivateKey: process.env.API_PRIVATE_KEY!,
    defaultOrganizationId: process.env.ORGANIZATION_ID!,
  });

  const response = await turnkeyClient.apiClient().getSwapStatus({
    organizationId: "<string> (Unique identifier for a given Organization.)",
    swapRequestId: "<string> (The swap_request_id returned by ExecuteSwap.)"
  });
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={"system"}
  {
    "status": "<string>",
    "swapKind": "<string>",
    "provider": "<string>",
    "inputToken": "<string>",
    "outputToken": "<string>",
    "inputAmount": "<string>",
    "originTxHash": "<string>",
    "destinationTxHashes": [
      "<string>"
    ],
    "outputAmount": "<string>",
    "refund": {
      "asset": "<string>",
      "amount": "<string>",
      "txHash": "<string>"
    },
    "updatedAt": "<string>",
    "error": {
      "reason": "<string>",
      "message": "<string>",
      "originTxError": {
        "message": "<string>",
        "revertChain": [
          {
            "address": "<string>",
            "errorType": "<string>",
            "displayMessage": "<string>",
            "unknown": {
              "selector": "<string>",
              "data": "<string>"
            },
            "native": {
              "nativeType": "<string>",
              "message": "<string>",
              "panicCode": "<string>"
            },
            "custom": {
              "errorName": "<string>",
              "paramsJson": "<string>"
            }
          }
        ],
        "solana": {
          "source": "<string>",
          "rpcCode": "<number>",
          "rpcMessage": "<string>",
          "transactionErrorJson": "<string>",
          "logs": [
            "<string>"
          ],
          "unitsConsumed": "<string>",
          "innerInstructionsJson": "<string>"
        },
        "eth": {
          "revertChain": [
            {
              "address": "<string>",
              "errorType": "<string>",
              "displayMessage": "<string>",
              "unknown": {
                "selector": "<string>",
                "data": "<string>"
              },
              "native": {
                "nativeType": "<string>",
                "message": "<string>",
                "panicCode": "<string>"
              },
              "custom": {
                "errorName": "<string>",
                "paramsJson": "<string>"
              }
            }
          ]
        }
      }
    }
  }
  ```
</ResponseExample>
