# Complete the Swap

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

```javascript

const SWAP_CONTRACT_ADDRESS_ON_DESTINATION = "0x..."; // get this from the docs for your network
const ABI = '{
    "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"
  }';

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

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

const response = await safeSwap.withdraw(swapInfo.targetContractId, secret, { gasLimit: 200000 });
return response.hash;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.safeswap.io/builders/api-integration-guide/perform-a-swap/complete-the-swap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
