# How to Swap

Performing a successful swap consists of a series of requests to our API which execute on a blockchain and require gas. These gas fees vary depending on the network. This API is currently used on Fanbase Mobile Wallet, Fanbase Browser Wallet, and Fanbase DeFi website..&#x20;

Follow these steps to swap ERC1155s with ERC20s using the API.

1. **Create an exchange instance and add liquidity**\
   To trade ERC1155s with ERC20s, first create an exchange instance with the exchange factory.\
   [https://agg1155.fanbase.io/v1/createNftExchangeInstance](https://api.fanbase.io/v1/createNftExchangeInstance)\
   This API endpoint creates the exchange instance. \[See 'NFT Swap API' page for details].\
   \
   Next, liquidity will be needed in the exchange instance.\
   [https://agg1155.fanbase.io/v1/addLiquidityToNftDex](https://api.fanbase.io/v1/addLiquidityToNftDex)\
   Use this API endpoint to add liquidity to the exchange instance.\
   See 'NFT Swap API' page for details about endpoints, and executing transactions returned from an endpoint to add liquidity. \[The transaction executer must have enough (amount) ERC1155s and ERC20s to add liquidity].
2. **Get a pair list to choose an exchange instance to swap on**\
   After the exchange is created and liquidity is added, the user must choose a swap.\
   \
   [https://agg1155.fanbase.io/v1/getPairList](https://api.fanbase.io/v1/getPairList)\
   This endpoint is to get the list of existing exchange instances. \[See 'NFT Swap API' page for details on getting the pair list].&#x20;
3. **Get the ERC20 amount to swap for an ERC1155**\
   To buy or swap for an ERC1155 NFT, the user must know its price.\
   \
   [https://agg115.fanbase.io/v1/getTokenToCurrencyPrice](https://api.fanbase.io/v1/getTokenToCurrencyPrice)\
   This endpoint gets the price of the ERC1155 in terms of the amount of ERC20s needed to conduct the transaction. Here, you fetch the 'price' before trading the NFT.
4. **Execute the 'BUY' transaction**\
   After choosing the exchange instance and getting the NFT 'price', the user must 'BUY' the endpoints to get an executable transaction array, and receive the NFT.\
   \
   [https://agg1155.fanbase.io/v1/buyToken](https://api.fanbase.io/v1/buyToken)\
   This endpoint fetches the transaction array, which includes approving the transaction of the ERC20 token and the release of the ERC1155 NFT.\
   Once the transaction array is fetched, the user must sign and execute the serial with his wallet.\
   \
   After all transactions are executed successfully, the swap operation ends.&#x20;
5. **Execute the 'SELL' transaction**\
   Like the 'BUY' operation, the 'SELL' operation also needs transaction data from API endpoints.\
   \
   [https://agg1155.fanbase.io/v1/sellToken](https://api.fanbase.io/v1/sellToken)\
   This endpoint fetches the transaction array which includes approving the transaction of the ERC1155 exchange instance and the receipt of the ERC20 token.\
   After getting the returned transaction, the user must sign and execute it with his wallet.\\

\*There are additional utility endpoints to fetch data about exchange instances and liquidity. To view those, go back to the NFT Swap API page.
