# HTLC

## What is HTLC?

HTLC, or Hashed Time-Locked Contract, is a smart contract mechanism used in blockchain networks to facilitate secure and trustless transactions. It employs cryptographic hash functions and time locks to ensure the conditional execution of a transaction.

With an HTLC, the sender locks a certain amount of assets in a contract, requiring the recipient to provide a specific pre-image within a specified time to claim the funds.

If the pre-image is not provided within the given timeframe, the funds are returned to the sender.

HTLCs are particularly useful in cross-chain transactions and atomic swaps, where two parties want to exchange cryptocurrencies without the need for intermediaries, ensuring neither party can cheat the other.

## **How SafeSwap Uses HTLC**

SafeSwap, as mentioned, is both a platform and protocol for atomic swaps, which in this case are peer-to-peer transfers of tokens between a user's own wallets across different blockchains, without requiring intermediaries.

For cross-chain transfers, the integrity, security and trustworthiness of the swaps are paramount, and that's where HTLCs come in.

When a user initiaties a swap on SafeSwap, an HTLC is created.

The HTLC ensures that:

1. The tokens are locked up securely in the correct Locked Token Pool. Same for unlocking.
2. The intended destination wallet can only claim the funds by providing a cryptographic proof within a set time frame. The SafeSwap protocol has this proof mechanism built-in and since it's browser-based, the swap should be done using the same device and browser. By doing this, users don't need to handle any code themselves.
3. If the necessary proof isn't provided on time, the swap is canceled, and the original source wallet can claim back the tokens.

Through this mechanism, SafeSwap can facilitate cross-chain transactions, such as [swapping SHA from vechain to Polygon](/user-guides/swap-tokens.md) for example, or any other supported blockchain, with a high level of trust and security.


---

# 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/technical/htlc.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.
