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;

Last updated