When the Swap is ready, it is time to claim the funds
The final step is to have the user claim the funds on the destination chain. After the user calls withdraw with the secret, the secret is exposed to the public and now our team can use that secret to withdraw the original funds and complete the atomic swap.
Example
constSWAP_CONTRACT_ADDRESS_ON_DESTINATION="0x..."; // get this from the docs for your networkconstABI='{"constant": false,"inputs": [ {"internalType":"bytes32","name":"_contractId","type":"bytes32" }, {"internalType":"bytes32","name":"_preimage","type":"bytes32" } ],"name": "withdraw","outputs": [ {"internalType":"bool","name":"","type":"bool" } ],"payable": false,"stateMutability": "nonpayable","type": "function" }';constprovider=newethers.providers.Web3Provider(window.ethereum);constsigner=provider.getSigner();constsafeSwap=newethers.Contract(SWAP_CONTRACT_ADDRESS,ABI, signer);constresponse=awaitsafeSwap.withdraw(swapInfo.targetContractId, secret, { gasLimit:200000 });returnresponse.hash;