π§ββοΈAuction
EnglishAuction
Implementation of an on-chain Elglish type auction for for both ERC-721 and ERC-1155 token standards.
EnglishAuction
This guide details how to interact with the EnglishAuction smart contract using Solidity. It focuses on the fundamental functionalities provided for managing English-style auctions for NFTs (ERC-721 and ERC-1155) on the Ethereum blockchain.
Overview
The EnglishAuction smart contract facilitates the creation, management, and finalization of on-chain auctions. It includes features such as bid management, automatic auction extensions, reserve price settings, and fee handling.
Auction Creation
Auctions are initialized when an NFT is transferred to the contract. This action triggers the onERC721Received function, which decodes additional data to set the auction's parameters, including the reserve price and commission details.
Key Parameters for Auction Creation:
_operator: Address initiating the NFT transfer.
_from: Seller's address.
_tokenId: ID of the NFT being auctioned.
_data: Encoded data containing the reserve price and commission information.
Bidding on Auctions
The contract differentiates between the first bid and subsequent bids to optimize gas costs and simplify logic.
First Bid:
Called via the
firstBidfunction.Marks the start of the auction and sets the ending time.
Must meet or exceed the reserve price.
Subsequent Bids:
Handled by the
bidfunction.Must be at least a certain percentage higher than the previous bid, defined by
_MIN_BID_RAISE.If placed within the final moments of the auction (
_EXTENSION_DURATION), the auction's ending time is extended.
Finalizing Auctions
Once an auction concludes (post the ending time), it can be finalized with the finalize function, which:
Transfers the NFT to the highest bidder.
Distributes the sale amount, minus any fees, royalties, and commissions.
Deletes the auction record to free up storage and refund gas.
Modifying Auctions
Before receiving any bids, auction parameters such as the reserve price and commission details can be updated using respective functions:
updateReservePriceupdateCommissionBps
These functions require that the caller is the auction's creator and that no bids have been placed yet.
Canceling Auctions
An auction can be canceled by the seller if no bids have been placed. The cancelAuction function:
Returns the NFT to the seller.
Deletes the auction record.
Administrative Functions
Contract administrators (typically the contract deployer) can adjust operational settings:
setFeeRecipient: Updates the address where auction fees are sent.setMarketFee: Adjusts the fee percentage taken from auction sales.
Constructor
When deploying the contract, initial settings for the fee recipient and the fee percentage must be provided.
Additional Considerations
The auction contract integrates with NFT standards to handle transfers securely and confirm actions with event logging for transparency.
Special care should be taken to manage gas costs, especially when finalizing auctions, which involve multiple state changes and transfers.
The contract uses a non-reentrancy pattern by updating auction states before making external calls (such as transferring ETH), although this pattern is not explicitly named in the contract.
By following this guide, developers can effectively deploy and interact with the EnglishAuction smart contract to conduct decentralized auctions for NFTs. This ensures a robust, transparent, and user-friendly mechanism for NFT sales on the Ethereum blockchain.
Last updated