Wait/Poll for the Swap

Wait for SafeSwap to set up the destination chain 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

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.

Last updated