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
  1. Builders
  2. API Integration Guide
  3. Perform a Swap

Cancel/Refund

If the Swap can't be completed, you can always refund.

The original funds can be reclaimed by the user if they no longer want to complete the swap (took too long, lost the secret, swap failed, etc.)

Example


const SWAP_CONTRACT_ADDRESS_ON_SOURCE_CHAIN = "0x..."; // get this from the docs for your network
const ABI = '{
    "constant": false,
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "_contractId",
        "type": "bytes32"
      }
    ],
    "name": "refund",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
  }';

const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();

const safeSwap = new ethers.Contract(SWAP_CONTRACT_ADDRESS_ON_SOURCE_CHAIN, ABI, signer);

const response = await safeSwap.refund(swapInfo.sourceContractId, { gasLimit: 200000 });
return response.hash;
PreviousComplete the SwapNextSmart Contract Details

Last updated 2 years ago

📖