Purchasing NFTs from a Sale

purchase_nfts<CURRENCY>(...) Purpose: Allows a buyer to purchase one or multiple NFTs directly from the sale by paying the required currency.

Key Parameters:

  • sale: A mutable reference to the NFTSale.

  • payment: A Coin<CURRENCY> containing enough value to cover the purchase.

  • asset_ids: A vector of the specific NFTs (by asset_id) the buyer wishes to purchase.

  • collection_cap: For checking deny list and other constraints.

  • ctx: The transaction context.

Process:

  1. Verify sale.is_active is true.

  2. Check that the buyer is not on the deny list.

  3. Validate the payment covers price_per_nft * number_of_NFTs.

  4. Deduct the NFTs from the sale, transfer them to the buyer, and deposit the payment into the sale’s currency balance.

  5. Emit an NFTPurchased event and update user balances.

Use Cases:

  • A collector buys 3 NFTs from a sale, paying the set price in the required currency.

  • Automated scripts purchase NFTs in batches if they match investment criteria.

Last updated