SafeSwap
Open SafeSwap
  • 👋Introduction to SafeSwap
  • Learn
    • 🤔How SafeSwap Works
    • 🪙SHA Token
    • ⛽Fee Structure
    • 💰Fee Distribution
    • 👑SafeNodes
    • 📚Glossary
  • User Guides
    • 🔄Swap Tokens
    • 📊Token Dashboard
  • Technical
    • ⚛️Cross-Chain Atomic Swaps
    • 🔐HTLC
    • 🛡️Security Measures
    • ⛓️Supported Blockchains
    • 👝Supported Wallets
    • 🕵️Audits
  • Builders
    • 🌍Hello World!
    • 🏗️Cross-Chain Use Cases
    • 🖥️Token Listing
    • 👨‍💻Whitelabel Integration
    • 📖API Integration Guide
      • Prerequisites
      • What is a Swap?
      • Perform a Swap
        • Initiate a Swap
        • Send Fees
        • Create the Swap in API
        • Wait/Poll for the Swap
        • Complete the Swap
        • Cancel/Refund
      • Smart Contract Details
      • Our Swap Addresses
      • API Details
  • About
    • Safe Haven
    • SafeTech
    • Support
Powered by GitBook
On this page
  • Example
  • Errors
  1. Builders
  2. API Integration Guide
  3. Perform a Swap

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.

PreviousCreate the Swap in APINextComplete the Swap

Last updated 1 year ago

📖