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

# Request status codes

> When submitting requests with Bungee, monitoring the status of requests is essential. This is an explainer of the different status codes returned by the Bungee API and how to interpret them.

> **API Reference**: Status Endpoint

## Checking Request Status[​](#checking-request-status "Direct link to Checking Request Status")

You can use the Bungee API endpoint to check the status of a request from Bungee Auto transactions and Bungee Manual crosschain swaps. The request hash can be either:

* The `requestHash` returned from a submit request (for Auto routes)
* The transaction hash (for Manual routes)

```javascript theme={null}
const BUNGEE_API_BASE_URL = "https://public-backend.bungee.exchange";

async function checkStatus(requestHash) {
  try {
    const response = await fetch(
      `${BUNGEE_API_BASE_URL}/api/v1/bungee/status?requestHash=${requestHash}`
    );
    const data = await response.json();
    if (!data.success) {
      const serverReqId = response.headers.get("server-req-id");
      throw new Error(
        `Status error: ${data.statusCode}: ${data.message}. server-req-id: ${serverReqId}`
      );
    }
    // It returns an array since we can have multiple requests in one requestHash
    return data.result[0];
  } catch (error) {
    console.error("Failed to check status:", error);
    throw error;
  }
}
```

### Manual samechain swaps[​](#manual-samechain-swaps "Direct link to Manual samechain swaps")

For Bungee Manual samechain swaps, the swap is executed in the same onchain transaction you submit. Check the receipt status to determine success.

```javascript theme={null}
// Example using viem
import { createPublicClient, http } from "viem";
import { ethereum } from "viem/chains";

const client = createPublicClient({ chain: ethereum, transport: http() });

async function checkManualSameChainTx(hash) {
  const receipt = await client.waitForTransactionReceipt({ hash });
  if (!receipt) {
    throw new Error("Transaction not found");
  }
  if (receipt.status !== "success") {
    throw new Error("Transaction failed/reverted");
  }
  return receipt;
}
```

## Status Code Enum[​](#status-code-enum "Direct link to Status Code Enum")

Bungee uses the following enum to represent the status of a request. These status codes are returned in the `bungeeStatusCode` field of the status response:

```typescript theme={null}
export enum RequestStatusEnum {
  PENDING = 0,
  ASSIGNED = 1,
  EXTRACTED = 2,
  FULFILLED = 3,
  SETTLED = 4,
  EXPIRED = 5,
  CANCELLED = 6,
  REFUNDED = 7,
}
```

## Status Code Descriptions[​](#status-code-descriptions "Direct link to Status Code Descriptions")

### PENDING (0)[​](#pending-0 "Direct link to PENDING (0)")

The request has been submitted to the Bungee Auto system but has not yet been picked up by a solver. This is the initial state of all requests.

### ASSIGNED (1)[​](#assigned-1 "Direct link to ASSIGNED (1)")

A solver has been assigned to the request and is working on it. The solver is preparing to execute the request.

### EXTRACTED (2)[​](#extracted-2 "Direct link to EXTRACTED (2)")

The solver has extracted the funds from the source chain and is in the process of executing the request.

### FULFILLED (3)[​](#fulfilled-3 "Direct link to FULFILLED (3)")

The request has been successfully executed on the destination chain. The funds have been delivered to the recipient address.

### SETTLED (4)[​](#settled-4 "Direct link to SETTLED (4)")

The request has been fully settled, meaning all operations have been completed and confirmed on both chains.

### EXPIRED (5)[​](#expired-5 "Direct link to EXPIRED (5)")

The request has expired because it was not processed within the specified time limit. This could happen if no solver was available or if there were network issues.

### CANCELLED (6)[​](#cancelled-6 "Direct link to CANCELLED (6)")

The request was cancelled, either by the user or by the system.

### REFUNDED (7)[​](#refunded-7 "Direct link to REFUNDED (7)")

The refund has been processed and the funds have been sent to the user's address. The `refund` object contains details about the transaction hash and chain ID.

**Refund recipient:**

* If refunded on the source chain:

  * Onchain: Funds are sent to the `msg.sender` of the `createRequest` transaction
  * API: Funds are sent to the user address if submitted via `submit` endpoint

* If refunded on the destination chain: Funds are sent to the `receiver` address

## Example Implementation with Polling[​](#example-implementation-with-polling "Direct link to Example Implementation with Polling")

Here's an example of how to poll for status updates until a transaction is complete:

```javascript theme={null}
// For Auto routes (using requestHash from submission)
let status;
const terminalStates = [3, 4, 5, 6, 7]; // FULFILLED, SETTLED, EXPIRED, CANCELLED, REFUNDED
do {
  await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait 5 seconds between checks
  console.log("Checking status...");
  try {
    status = await checkStatus(submitResult.requestHash);
    console.log("Status details:", status.bungeeStatusCode);
  } catch (error) {
    console.error("Failed to check status:", error?.message || "Unknown error");
  }
} while (!status || !terminalStates.includes(status.bungeeStatusCode));

// Handle terminal states
if (status) {
  const code = status.bungeeStatusCode;
  if (code === 3) {
    // FULFILLED
    console.log(
      "Transaction complete:",
      "\n- Hash:",
      status.destinationData?.txHash || "Transaction hash not available"
    );
  } else if (code === 4) {
    // SETTLED
    console.log("Transaction settled:", status.destinationData?.txHash || "Transaction hash not available");
  } else if (code === 5) {
    // EXPIRED
    console.log("Request expired. The request was not processed within the time limit.");
  } else if (code === 6) {
    // CANCELLED
    console.log("Request cancelled.");
  } else if (code === 7) {
    // REFUNDED
    console.log("Request refunded:", status.refund?.txHash || "Refund transaction hash not available");
  }
}
```

```javascript theme={null}
// For Manual routes (using transaction hash)
let status;
const terminalStates = [3, 4, 5, 6, 7]; // FULFILLED, SETTLED, EXPIRED, CANCELLED, REFUNDED
do {
  await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait 5 seconds between checks
  console.log("Checking status...");
  try {
    status = await checkStatus(transactionHash);
    console.log("Status details:", status?.bungeeStatusCode || "Pending");
  } catch (error) {
    console.error("Failed to check status:", error?.message || "Unknown error");
  }
} while (!status || !terminalStates.includes(status.bungeeStatusCode));

// Handle terminal states
if (status) {
  const code = status.bungeeStatusCode;
  if (code === 3) {
    // FULFILLED
    console.log(
      "Transaction complete:",
      "\n- Hash:",
      status.destinationData?.txHash || "Transaction hash not available"
    );
  } else if (code === 4) {
    // SETTLED
    console.log("Transaction settled:", status.destinationData?.txHash || "Transaction hash not available");
  } else if (code === 5) {
    // EXPIRED - terminal failure
    const errorMessage = `Request expired (status code: ${code}). The request was not processed within the time limit. Status details: ${JSON.stringify(status)}`;
    console.error(errorMessage);
    throw new Error(errorMessage);
  } else if (code === 6) {
    // CANCELLED - terminal failure
    const errorMessage = `Request cancelled (status code: ${code}). Status details: ${JSON.stringify(status)}`;
    console.error(errorMessage);
    throw new Error(errorMessage);
  } else if (code === 7) {
    // REFUNDED - terminal failure
    const errorMessage = `Request refunded (status code: ${code}). Refund transaction hash: ${status.refund?.txHash || "not available"}. Status details: ${JSON.stringify(status)}`;
    console.error(errorMessage);
    throw new Error(errorMessage);
  }
}
```
