Simple Swap Functionality Using 1inch

Overview

Our Decentralized Exchange (DEX) provides a seamless and efficient token swapping experience by leveraging the 1inch API. This documentation outlines how our swap functionality works. Users can easily exchange tokens across different blockchain networks while benefiting from real-time price updates and robust error handling.

Key Features

  • Efficient Token Swaps: Users can swap tokens quickly and easily using the 1inch API.

  • Custom Chain Integration: Our DEX utilizes a custom chain (shido) specifically designed for the Shido network, enhancing the swapping experience.

  • Real-Time Price Fetching: The DEX fetches up-to-date token prices to ensure accurate swap calculations.

  • User-Friendly Interface: The DEX provides an intuitive interface for selecting tokens, inputting amounts, and confirming swaps.

  • Error Handling: Comprehensive error handling ensures users are informed of any issues during the swap process.

Step-by-Step Process

Step 1: User Interface Interaction

Users begin by navigating to the Swap section of the DEX. Here, they can select the tokens they wish to swap, input the amounts, and view real-time price information. The interface is designed to be user-friendly, guiding users through the selection process.

Step 2: Token Selection

Once the user selects the tokens, the DEX displays a list of available tokens for each chain, allowing users to make informed decisions based on their preferences. The DEX supports token swaps on the Shido network using our custom chain (9008).

Step 3: Input Amount

After selecting the tokens, users input the amount they wish to swap. The DEX performs real-time validation to ensure that the input amount meets the minimum requirements for the swap.

Step 4: Fetching Swap Route

Upon entering the amount, the DEX automatically fetches the optimal swap route using the 1inch API. This process involves sending a request that includes the selected tokens, amounts, and user address. The API returns the best route for the swap, including estimated amounts and any applicable fees.

Step 5: Approval for Token Spending

Before executing the swap, the DEX checks whether the user has approved the necessary token spending. If the allowance is insufficient, the DEX prompts the user to approve the required amount. This step is crucial for ensuring that the DEX can execute the swap on behalf of the user.

Step 6: Confirming the Swap

Once the user has approved the token spending, they can confirm the swap. The DEX constructs the transaction data and initiates the swap process. Users are presented with a summary of the transaction, including the tokens being swapped, amounts, and estimated fees.

Step 7: Executing the Transaction

The DEX sends the transaction to the blockchain, executing the swap. For swaps on the Shido network, the DEX utilizes our custom chain (9008) to facilitate the transaction. Users receive real-time updates on the transaction status, ensuring transparency throughout the process. If the transaction is successful, users are notified with a confirmation message and provided with the transaction hash for tracking purposes.

Step 8: Error Handling and Notifications

In the event of an error during the swap process, the DEX provides clear and informative error messages. This ensures that users understand the nature of the issue and can take appropriate action, whether it be adjusting their input or checking their wallet settings.

Step 9: Transaction History

After the swap is completed, the DEX records the transaction details, allowing users to view their swap history. This feature enhances user experience by providing transparency and accountability for all transactions conducted on the platform.

Conclusion

The swap functionality on our DEX, powered by the 1inch API and our custom chain (9008) for the Shido network, offers users a robust and efficient way to exchange tokens. By following the outlined steps, users can easily navigate the swapping process, ensuring a seamless experience.

Last updated