Swap

From this section, you can request for trading details and swap with SDK eaisly

swapInfo

Copy

const res: IResType<ISwapInfo>= await floorswap.swap.swapInfo({
  collection: '...',
  swapType: 1,
  slippage?: 5,
  count?: 1,
  nftList?: ['5'],
}: ISwapInfoParams)

interface ISwapInfoParams {
  collection: string;
  swapType: number;
  slippage?: number;
  count?: number;
  nftList?: string[];
}

interface IResType<T> {
  code: string;
  message: string;
  success: boolean;
  data: T;
}

interface ISwapInfo {
  swapList: {
    pairAddress: string;
    nftList: string[];
  }[];
  signature: string;
  tokenAmount: number;
  protocolFee: number;
  lpFee: number;
  slippageAmount: number;
}

ISwapInfoParams

NameTypeRequiredDescription

collection

string

true

Collection address

swapType

number

true

Type of swap:

  1. swap token to NFT

  2. swap NFT to token

slippage

number

false

Slippage

count

number

false

Amount of NFTs. It's needed when vaule of "swapType" is 1

nftList

string[]

false

List of NFTs. It's needed when value of "swapType" is 2

ISwapInfo

NameTypeDescriptionExample

swapList

object[]

- pairAddress

string

Position address

0xe012baf811cf9c05c408e879c399960d1f305903

- nftList

string[]

List of NFTs

["5"]

signature

string

signature

tokenAmount

number

Amount of tokens

5

protocolFee

number

Protocol fee

0.5

lpFee

number

Fee earned for liquidity provider

0.5

slippageAmount

number

The value of slippage

5

swap

Swap ETH for NFTs

Copy

const response:ContractTransactionResponse = await floorswap.swap.swapTokenForNft({
  signer: signer,
  collection: "0x1234...",
  count: 2,
  slippage: 0.02,
}: ISwapTokenForNftParams & { signer: ethers.Signer });

interface ISwapTokenForNftParams {
  collection: string;
  slippage: number;
  count: number;
}

ISwapTokenForNftParams

NameTypeRequiredDescription

collection

string

true

Collection address

slippage

number

true

The value of slippage

count

number

true

Amount of NFTs

Swap NFTs for ETH

Copy

const response:ContractTransactionResponse = await floorswap.swap.swapNftForToken({
  signer: signer,
  collection: "0x1234...",
  nftIds: ["57", "68"],
  slippage: 0.02,
}: ISwapNftForTokenParams & { signer: ethers.Signer });

interface ISwapNftForTokenParams {
  collection: string;
  slippage: number;
  nftIds: string[];
}

ISwapNftForTokenParams

NameTypeRequiredDescription

collection

string

true

Collection address

slippage

number

true

The value of slippage

nftIds

string[]

true

List of NFTs

swapAnyNftForToken

Swap any NFTs for ETH.

Copy

const collection = "0x1234..."; // Collection contract address
const amount = 2;
const slippage = 0.02; //0.02 = 2%
await floorswapSDK.swap.swapAnyNftForToken({
  signer: signer,
  collection: nftAddress,
  count: nftIds,
  slippage: slippage,
}: ISwapAnyNftForTokenParams & { signer: ethers.Signer });

interface ISwapAnyNftForTokenParams {
  collection: string;
  slippage: number;
  amount: number;
}

ISwapAnyNftForTokenParams

NameTypeRequiredDescription

collection

string

true

collection address

slippage

number

true

The value of slippage

amount

number

true

amount of NFTs you wanna swap

Last updated