Swap
This page illustrate how to integrate PiperX swap functionality to your Dapps and website.
Integrating Swap to website
Integrating the PiperX swap functionality to your website makes it easy for you to leverge the liquidity from PiperX without the needs of maintain your own pools. Some example applications including swapping staked $IP tokens to $IP tokens on the LSD website, allow users to buy NFT with stable coins (auto swap stable coins to $IP) on the NFT marketplace.
Steps to Integration
There are three steps in conducting a swap: 1) prepare input, 2) approve tokens, 3) conduct swap. You need to install PiperX sdk and import it to proceed.
Prepare Input
You need the following inputs before you can conduct a swap
Note that, if you are swapping $IP token, you should pass in the PiperX wrapped $IP token address, because the $IP token is not a ERC-20 token. For example, if you are swapping from staked $IP token to $IP token, please use wrapped $IP address WIP_ADDRESS
Approve tokens
Conduct swap
Depends on the swaps that you plan to do, we will call different functions from the PiperX V2 contract. One could use the follow code to deal with different swap cases.
Last updated