This function allows users to buy NFTs from the sell pool.

Request Parameters
ParameterTypeDescriptionExample
swapListRobustPairSwapSpecific[]Data Content: [[[Contract Address, [Token ID 1, Token ID 2, ...],[Amount 1, Amount 2]], Expected Payment Amount]][[['0x4485aD38f3fe1DA3856155496f7fEce05d4C3B56', 3104', [1,2,3],[1,2,3]], 1000000000000000000]]
inputAmountuint256buy nft token amount
nftRecipientaddressNFT recipient address, usually msg.sender0x0a9EE17c7B649dd30Db1450537576d313FF862C7
deadlineuint256Expiration timestamp1665208404

call router contract

Additional
// swapList具体结构
function swapERC20ForSpecificNFTs(
    PairSwapSpecific[] calldata swapList,
    uint256 inputAmount,
    address nftRecipient,
    uint256 deadline
)
    external
    checkDeadline(deadline)
    returns (uint256 remainingValue)
    
struct RobustPairSwapSpecific {
        PairSwapSpecific swapInfo;
        uint256 maxCost;
}

struct PairSwapSpecific {
        LSSVMPair pair;
        uint256[] nftIds;
        uint256[] nftCounts;
}
Return Parameters
ParameterTypeDescriptionExample
remainingValueuint256Unspent ETH1000000000000000

ABI

function robustSwapERC20ForSpecificNFTs(tuple(tuple(address,uint256[],uint256[]),uint256)[],uint256,address,uint256) public payable returns (uint256)

Expected Payment Amount and Current NFT Price

Refer to the calculation library for detail.

When buying NFTs, a maximum expected cost needs to be set, and transactions exceeding this value will not be made.
//Example: Scenario: A user buys an NFT from a linear pool
mathLib.Linear.buy(1, 0.1, 0.003, 0.003, 1, 0, 'read')
//Return Value: The total price (totalETH) is priceData.userBuyPrice, and the price displayed on the page for that NFT is currentPrice.userBuyPrice
{
  priceData: {
    delta: 0.1,
    spotPrice: 1,
		userBuyPrice: 0.994,   --The amount of ETH the user can sell NFTs for
    poolBuyPrice: 0.997,    --The amount of ETH that the pool will spend to buy NFTs
    poolBuyPriceFee: 0.003,
    userSellPriceFee: 0.006
  },
  currentPrice: { userBuyPrice: 0.994 },   --The current price
  nextPrice: { userSellPrice: 0.8945999999999998 }  --The price of the next NFT
}

Code Example

import { ethers, utils } from 'ethers';

const DEADLINE = Date.parse(new Date()) / 1000 + 60 * 3600;
const abi = ['function robustSwapERC20ForSpecificNFTs(tuple(tuple(address,uint256[],uint256[]),uint256)[],uint256,address,uint256) public payable returns (uint256)'];
const signer = new ethers.providers.Web3Provider(window?.ethereum).getSigner();
const contract = new ethers.Contract(routerAddress, abi, signer);
const txResult = await contract.robustSwapETHForSpecificNFTs(
	swapList,
  inputAmount,
  nftRecipient,
  DEADLINE
);

Detailed and complete demo: https://github.com/EZswap-Labs/api-demo