# Let's Swap

**Always practice solid risk management rules when experimenting with swaps: use the correct slippage values and trusted currency pairs, double-check the numbers before confirming, and compare external price sources.**

Throughout this guide, we will use [Router](/smart-contracts.md#router) and try to swap Aptos coins to test BTC.

Let's create a new module and import the router into it:

{% embed url="<https://gist.github.com/borispovod/62ba3b63a335267221922db3eaa05891>" %}
Basic module
{% endembed %}

As you try to compile the code above, you will get a warning; don't worry, it's fine.&#x20;

Now let's add the dependencies we will need for this experiment, as well as a basic entry function that we can call in a transaction later:

{% embed url="<https://gist.github.com/borispovod/1a1ec9b2ae21c0e0d75775f4fd9e6ecd>" %}

Let's withdraw `1000` Aptos coins from an account and see how many BTC we can get in exchange:

{% embed url="<https://gist.github.com/borispovod/c0d434a0c944009d83e18b2b7187b98f>" %}

The provided code above wouldn't still compile as we can't drop Aptos coins; at the same time, it already shows how much BTC we can get back for 1000 Aptos coins because of `get_amount_out` function.

Now let's indeed do a swap and finally deposit the swapped coins on our account:

{% embed url="<https://gist.github.com/borispovod/019a3b99214845278d2339bef40aaf2c>" %}

Everything worked out well; using `swap_exact_coin_for_coin,` we have swapped Aptos coins for BTC.

This looks simple, but what if someone decided to front-run us? Let's add some basic slippage checks for the minimum amount of BTC we want to receive (afterwards we can remove `get_amount_out`).

{% embed url="<https://gist.github.com/borispovod/871dfeddbffba5396e5a605a46d7ef9c>" %}

All done. In the same way, you can try another function: `router::swap_coin_for_exact_coin` (see [Router](/smart-contracts.md#router) docs).

*An important note regarding decentralized AMM securities and user transactions:*

* *Always use safety checks.*
* *Never swap tokens without a slippage value provided offline.*
* *Use external price feeds or oracles (even the* [*Basic Oracle*](/integration/basic-oracle.md) *can be a good option).*


---

# 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.liquidswap.com/integration/lets-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.
