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

Create the Swap in API

After creating a Swap in the contract, send it to our API so we can act on it.

Example

const response = ... // response is from the smart contract call when you created the swap.
const receipt = await provider.getTransactionReceipt(response.transactionId);

const contractId = receipt.logs.find(log => log.address.toLowerCase() === SWAP_CONTRACT_ADDRESS.toLowerCase()).topics[1];

const apiResponse = await fetch(`${SWAP_API_URL}/swaps`, {
    method: "POST",
    body: JSON.stringify({
        sourceChain: "VECHAIN",
        sourceContractId: contractId,
        sourceSender: usersAddressOnVechain,
        sourceFeeTx: originalFeeTxId,
        targetChain: "ETHEREUM",
        targetReceiver: usersAddressOnEthereum,
        targetTokenAddress: TOKEN_ADDRESS_ON_ETHEREUM,
        targetFeeTx: destinationFeeTxId
    }),
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'MY_API_KEY'
    }
});

  if (!response.ok) {
    throw new Error(response);
  }

  const result = await response.json();
  const swapId = result.id;
PreviousSend FeesNextWait/Poll for the Swap

Last updated 1 year ago

📖