# Wait/Poll for the Swap

After you have successfully set up a Swap, you need to wait for SafeSwap to complete its portion of the process. This portion involves setting up a smart contract Swap on the destination chain just like you did on the original chain. It is using the Atomic Swap techniques to set up a Swap that the user can claim using their original secret.

In order to find the status of the Swap, you can poll the SafeSwap API at a regular interval.

### Example

```javascript
let swapInfo = null;
const intervalId = setInterval(() => {
      const apiResponse = await fetch(`${SWAP_API_URL}/swaps?swapId=${swapId}`, {  
          headers: {
            'Content-Type': 'application/json',
            'X-API-KEY': 'MY_API_KEY'
          }
      });
      
      const result = await apiResponse.json();
      swapInfo = result[0];
      if (swapInfo.targetContractId) {
          console.log("the swap is ready");
          clearInterval(intervalId);
      } else {
          console.log("Still waiting for the swap to be set up");
      }
}, 3000);

```

### Errors

If there is an error during this process, `swapInfo.erroredAt` will be populated with a timestamp indicating that there is an error and this swap cannot be completed. The user has the option to wait for the timelock to expire (4 hours) and reclaim their original funds. The user can try again.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.safeswap.io/builders/api-integration-guide/perform-a-swap/wait-poll-for-the-swap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
