How to Swap
On this page you will find the guide to using the Fanbase ERC1155 swap API for ERC1155-ERC20 pairs.
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..
Follow these steps to swap ERC1155s with ERC20s using the API.
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 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 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].
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 This endpoint is to get the list of existing exchange instances. [See 'NFT Swap API' page for details on getting the pair list].
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 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.
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 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.
Execute the 'SELL' transaction Like the 'BUY' operation, the 'SELL' operation also needs transaction data from API endpoints. https://agg1155.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.
Last updated