# ERC-20 SWAP

### DESCRIPTION

The swap token contract enables the exchange of two ERC-20 tokens between two parties. The contract takes the addresses of the two tokens, the respective owners, and the amounts to be transferred. One of the owners calls the swap() function to confirm their ownership and the sanctioned allowance for using the tokens. The tokens are then transferred between the owners using the \_safeTransferFrom() function.

### FUNCTIONS

1. **Swap():** This function allows the owners of the two tokens to swap them. The function checks that the caller is one of the owners and that the approved allowance for spending the tokens is sufficient. It then transfers the tokens between the owners in a 1:1 ratio.

### EXTRA PARAMETERS

**Contract Level :** Easy

**Utility Tags:** ERC20, Reentrancy, Token Swap

* **Token1: address(String)**
* **Owner1: address**
* **Amount1: Integer**
* **Token2: address**
* **Owner2: address**
* **Amount2: Integer**

### USES&#x20;

1. **Peer-to-Peer Token Swapping:** The contract allows individuals to swap tokens directly without relying on centralized exchanges. This can be useful for private token trades or negotiated token exchanges.
2. **Decentralized Token Exchanges (DEXs):** The contract can be integrated into decentralized exchanges to facilitate token swaps between users. It provides a mechanism for users to directly exchange tokens with each other on-chain.
3. **Token Liquidity Provision:** Liquidity providers in decentralized finance (DeFi) protocols can utilize the contract to swap their tokens with other liquidity providers, rebalancing their portfolios or adjusting their token allocations.
4. **Over-the-Counter (OTC) Trading:** The contract can be used for over-the-counter trading of tokens between parties who have agreed on specific swap conditions and want to settle the trade directly.
5. **Token Redistribution:** In certain cases, token holders or project teams might need to redistribute tokens among different addresses, such as during token airdrops, token allocations, or token migrations. The contract can facilitate the redistribution process by allowing the owners to swap tokens directly.


---

# 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://sinqlarity.gitbook.io/sinqlarity-docs/contract-details/erc-20-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.
