### Install Test Dependencies for thirdweb Contracts Source: https://github.com/thirdweb-dev/contracts/blob/main/README.md Commands to install project and test dependencies required for building and testing thirdweb contracts using yarn and forge. ```bash yarn forge install ``` -------------------------------- ### Install thirdweb Contracts Source: https://github.com/thirdweb-dev/contracts/blob/main/README.md Instructions for installing thirdweb contracts in your project. Choose between Forge for Solidity projects or npm for JavaScript/TypeScript based projects. ```shell forge install https://github.com/thirdweb-dev/contracts ``` ```bash npm i @thirdweb-dev/contracts ``` -------------------------------- ### Get Total Listings Count (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Retrieves the total number of listings that have been created on the platform. ```Solidity function totalListings() external view returns (uint256); ``` ```APIDOC Function: totalListings Description: Returns the total number of listings created so far. Returns: uint256 - The total number of listings. ``` -------------------------------- ### Get All Listings by ID Range (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Fetches all listings within a specified ID range (inclusive). It includes the definition of `TokenType`, `Status`, and `Listing` struct used in the return type. ```Solidity enum TokenType { ERC721, ERC1155 } enum Status { UNSET, CREATED, COMPLETED, CANCELLED } struct Listing { uint256 listingId; address listingCreator; address assetContract; uint256 tokenId; uint256 quantity; address currency; uint256 pricePerToken; uint128 startTimestamp; uint128 endTimestamp; bool reserved; TokenType tokenType; Status status; } function getAllListings(uint256 startId, uint256 endId) external view returns (Listing[] memory listings); ``` ```APIDOC Function: getAllListings Description: Returns all listings between the start and end Id (both inclusive) provided. Parameters: startId: uint256 - Inclusive start listing Id endId: uint256 - Inclusive end listing Id Returns: listings: Listing[] memory - An array of Listing structs. Structs and Enums: enum TokenType { ERC721, ERC1155 } enum Status { UNSET, CREATED, COMPLETED, CANCELLED } struct Listing { uint256 listingId; address listingCreator; address assetContract; uint256 tokenId; uint256 quantity; address currency; uint256 pricePerToken; uint128 startTimestamp; uint128 endTimestamp; bool reserved; TokenType tokenType; Status status; } ``` -------------------------------- ### Get Single Listing by ID (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Retrieves a single listing based on its unique listing ID. ```Solidity function getListing(uint256 listingId) external view returns (Listing memory listing); ``` ```APIDOC Function: getListing Description: Returns a listing at the provided listing ID. Parameters: listingId: uint256 - The ID of the listing to fetch. Returns: listing: Listing memory - The Listing struct for the given ID. ``` -------------------------------- ### Get All Auctions by ID Range (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Returns an array of all auctions within a specified range of auction IDs, inclusive of both the start and end IDs. ```solidity function getAllAuctions(uint256 startId, uint256 endId) external view returns (Auction[] memory auctions); ``` ```APIDOC getAllAuctions(startId: uint256, endId: uint256) external view returns (Auction[] memory auctions) startId: uint256 - Inclusive start auction Id endId: uint256 - Inclusive end auction Id ``` -------------------------------- ### Retrieve All Offers within a Range (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Returns an array of all offers, inclusive, between a specified start and end offer ID. This function is useful for paginating or fetching a batch of offers from the marketplace. ```Solidity function getAllOffers(uint256 startId, uint256 endId) external view returns (Offer[] memory offers); ``` ```APIDOC Parameters: startId: Inclusive start offer Id. endId: Inclusive end offer Id. ``` -------------------------------- ### Get Total Number of Marketplace Offers (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Retrieves the total count of all offers that have been created on the marketplace smart contract up to the current point. ```Solidity function totalOffers() external view returns (uint256); ``` -------------------------------- ### Get Winning Bid Details (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Retrieves the details of the winning bid for a specific auction, including the bidder's address, the currency used, and the winning bid amount. ```solidity function getWinningBid(uint256 auctionId) external view returns ( address bidder, address currency, uint256 bidAmount ); ``` ```APIDOC getWinningBid(auctionId: uint256) external view returns (bidder: address, currency: address, bidAmount: uint256) auctionId: uint256 - The unique ID of an auction. ``` -------------------------------- ### Get All Valid Listings by ID Range (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Retrieves all valid listings within a specified ID range (inclusive). A valid listing is active, and its creator still owns and has approved the Marketplace to transfer the listed NFTs. ```Solidity function getAllValidListings(uint256 startId, uint256 endId) external view returns (Listing[] memory listings); ``` ```APIDOC Function: getAllValidListings Description: Returns all valid listings between the start and end Id (both inclusive) provided. A valid listing is where the listing is active, as well as the creator still owns and has approved Marketplace to transfer the listed NFTs. Parameters: startId: uint256 - Inclusive start listing Id endId: uint256 - Inclusive end listing Id Returns: listings: Listing[] memory - An array of Listing structs. ``` -------------------------------- ### Get Total Auctions Count (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Returns the total number of auctions that have been created on the contract so far. ```solidity function totalAuctions() external view returns (uint256); ``` ```APIDOC totalAuctions() external view returns (uint256) ``` -------------------------------- ### Solidity ClaimCondition Struct Definition Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/drop/drop.md Defines the structure for a single claim condition, specifying parameters like start time, maximum claimable supply, quantity limits per wallet, and an optional Merkle root for allowlisting. This struct is fundamental for setting restrictions on token minting. ```solidity struct ClaimCondition { uint256 startTimestamp; uint256 maxClaimableSupply; uint256 supplyClaimed; uint256 quantityLimitPerWallet; bytes32 merkleRoot; uint256 pricePerToken; address currency; } ``` -------------------------------- ### APIDOC: ClaimCondition Struct Definition Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/signature-drop/signatureDrop.md Defines the `ClaimCondition` struct, which specifies the parameters and restrictions for claiming lazy minted tokens, such as start time, supply limits, price, and currency. This struct is fundamental for configuring token distribution rules. ```APIDOC struct ClaimCondition { uint256 startTimestamp; uint256 maxClaimableSupply; uint256 supplyClaimed; uint256 quantityLimitPerTransaction; uint256 waitTimeInSecondsBetweenClaims; bytes32 merkleRoot; uint256 pricePerToken; address currency; } Parameters: startTimestamp: uint256 - The unix timestamp after which the claim condition applies. The same claim condition applies until the startTimestamp of the next claim condition. maxClaimableSupply: uint256 - The maximum total number of tokens that can be claimed under the claim condition. supplyClaimed: uint256 - At any given point, the number of tokens that have been claimed under the claim condition. quantityLimitPerTransaction: uint256 - The maximum number of tokens that can be claimed in a single transaction. waitTimeInSecondsBetweenClaims: uint256 - The least number of seconds an account must wait after claiming tokens, to be able to claim tokens again.. merkleRoot: bytes32 - The allowlist of addresses that can claim tokens under the claim condition. pricePerToken: uint256 - The price required to pay per token claimed. currency: address - The currency in which the pricePerToken must be paid. ``` -------------------------------- ### Cancel an Existing English Auction (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Enables the creator of an auction to cancel it using its unique auction ID. Cancellation is only possible if no bids have been placed on the auction yet, or if the auction hasn't started. ```APIDOC function cancelAuction(uint256 auctionId) external; Parameters: auctionId: uint256 - The unique ID of the auction to cancel. ``` -------------------------------- ### Get All Valid Auctions by ID Range (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Returns an array of all valid auctions within a specified range of auction IDs, inclusive. A valid auction is defined as one that is currently active, and for which the creator still owns and has approved the Marketplace to transfer the auctioned NFTs. ```solidity function getAllValidAuctions(uint256 startId, uint256 endId) external view returns (Auction[] memory auctions); ``` ```APIDOC getAllValidAuctions(startId: uint256, endId: uint256) external view returns (Auction[] memory auctions) startId: uint256 - Inclusive start auction Id endId: uint256 - Inclusive end auction Id ``` -------------------------------- ### Compile thirdweb Smart Contracts Source: https://github.com/thirdweb-dev/contracts/blob/main/README.md Command to compile thirdweb smart contracts using the Forge build tool, preparing them for deployment or testing. ```bash forge build ``` -------------------------------- ### APIDOC: `createPack` Function Parameters Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/pack/pack.md Documentation for the parameters required by the `createPack` function, detailing `contents`, `numOfRewardUnits`, `packUri`, `openStartTimestamp`, `amountDistributedPerOpen`, and `recipient`, explaining their roles in pack creation. ```APIDOC createPack(contents, numOfRewardUnits, packUri, openStartTimestamp, amountDistributedPerOpen, recipient): contents: Tokens/assets packed in the set of pack. numOfRewardUnits: Number of reward units for each asset, where each reward unit contains per unit amount of corresponding asset. packUri: The (metadata) URI assigned to the packs created. openStartTimestamp: The timestamp after which packs can be opened. amountDistributedPerOpen: The number of reward units distributed per open. recipient: The recipient of the packs created. ``` -------------------------------- ### Run Tests for thirdweb Smart Contracts Source: https://github.com/thirdweb-dev/contracts/blob/main/README.md Command to execute automated tests for thirdweb smart contracts using the Forge test runner, ensuring contract functionality and integrity. ```bash forge test ``` -------------------------------- ### API Reference for DirectListings Extension Smart Contract Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md This section provides an API overview for the DirectListings extension smart contract, detailing its primary function within the thirdweb Marketplace ecosystem. ```APIDOC DirectListings: type: extension smart contract description: Allows buying and selling of NFTs (ERC-721 or ERC-1155) for a fixed price. ``` -------------------------------- ### thirdweb Contracts Repository Directory Structure Source: https://github.com/thirdweb-dev/contracts/blob/main/README.md An overview of the thirdweb contracts repository's directory structure, categorizing contracts into extensions, base, prebuilt, infrastructure, EIP implementations, libraries, and external dependencies. ```text contracts | |-- extension: "extensions that can be inherited by NON-upgradeable contracts" | |-- interface: "interfaces of all extension contracts" | |-- upgradeable: "extensions that can be inherited by upgradeable contracts" | |-- [$prebuilt-category]: "legacy extensions written specifically for a prebuilt contract" | |-- base: "NON-upgradeable base contracts to build on top of" | |-- interface: "interfaces for all base contracts" | |-- upgradeable: "upgradeable base contracts to build on top of" | |-- prebuilt: "audited, ready-to-deploy thirdweb smart contracts" | |-- interface: "interfaces for all prebuilt contracts" | |--[$prebuilt-category]: "feature-based group of prebuilt contracts" | |-- unaudited: "yet-to-audit thirdweb smart contracts" | |-- [$prebuilt-category]: "feature-based group of prebuilt contracts" | |-- infra: "onchain infrastructure contracts" | |-- interface: "interfaces for all infrastructure contracts" | |-- eip: "implementations of relevant EIP standards" | |-- interface "all interfaces of relevant EIP standards" | |-- lib: "Solidity libraries" | |-- external-deps: "modified / copied over external dependencies" | |-- openzeppelin: "modified / copied over openzeppelin dependencies" | |-- chainlink: "modified / copied over chainlink dependencies" | |-- legacy-contracts: "maintained legacy thirdweb contracts" ``` -------------------------------- ### Buy NFTs from Listing (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Allows a buyer to purchase NFTs from an existing listing. This function is payable and requires the buyer to meet several criteria, including sufficient funds, marketplace approval, and matching expected total price. ```Solidity function buyFromListing( uint256 listingId, address buyFor, uint256 quantity, address currency, uint256 expectedTotalPrice ) external payable; ``` ```APIDOC Function: buyFromListing Description: Buy NFTs from a listing. Parameters: listingId: uint256 - The unique ID of the listing to buy NFTs from. buyFor: address - The recipient of the NFTs being bought. quantity: uint256 - The quantity of NFTs to buy from the listing. currency: address - The currency to use to pay for NFTs. expectedTotalPrice: uint256 - The expected total price to pay for the NFTs being bought. Criteria that must be satisfied: - The buyer must own the total price amount to pay for the NFTs being bought. - The buyer must approve the Marketplace to transfer the total price amount to pay for the NFTs being bought. - If paying in native tokens, the buyer must send exactly the expected total price amount of native tokens along with the transaction. - The buyer’s expected total price must match the actual total price for the NFTs being bought. - The buyer must buy a non-zero quantity of NFTs. - The buyer must not attempt to buy more NFTs than are listed at the time. - The buyer must pay in a currency approved by the listing creator. ``` -------------------------------- ### Accept an NFT Offer (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Allows the owner of the NFTs to accept an offer made for their tokens. Successful acceptance requires that the caller owns and has approved the marketplace to transfer the tokens, and that the offeror still holds and has approved the marketplace to transfer the offered currency. ```Solidity function acceptOffer(uint256 offerId) external; ``` ```APIDOC Parameters: offerId: The unique ID of the offer. Criteria: - The caller of the function must own and approve Marketplace to transfer the tokens for which the offer is made. - The offeror must still own and have approved Marketplace to transfer the requisite amount currency offered for the NFTs wanted. ``` -------------------------------- ### Create NFT Listing on Marketplace (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Allows users to list ERC721 or ERC1155 NFTs for sale at a fixed price on the marketplace. Requires ownership of the NFTs and prior approval for the marketplace contract to transfer them. The listing can be configured with specific start/end times and currency. ```Solidity struct ListingParameters { address assetContract; uint256 tokenId; uint256 quantity; address currency; uint256 pricePerToken; uint128 startTimestamp; uint128 endTimestamp; bool reserved; } function createListing(ListingParameters memory params) external returns (uint256 listingId); ``` ```APIDOC Function: createListing(ListingParameters memory params) returns (uint256 listingId) Description: List NFTs (ERC721 or ERC1155) for sale at a fixed price. Parameters: assetContract (address): The address of the smart contract of the NFTs being listed. tokenId (uint256): The tokenId of the NFTs being listed. quantity (uint256): The quantity of NFTs being listed. This must be non-zero, and is expected to be 1 for ERC-721 NFTs. currency (address): The currency in which the price must be paid when buying the listed NFTs. The address considered for native tokens of the chain is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE pricePerToken (uint256): The price to pay per unit of NFTs listed. startTimestamp (uint128): The UNIX timestamp at and after which NFTs can be bought from the listing. endTimestamp (uint128): The UNIX timestamp at and after which NFTs cannot be bought from the listing. reserved (bool): Whether the listing is reserved to be bought from a specific set of buyers. Returns: listingId (uint256): The unique ID of the newly created listing. Criteria: - The listing creator must own the NFTs being listed. - The listing creator must have already approved Marketplace to transfer the NFTs being listed (since the creator is not required to escrow NFTs in the Marketplace). - The listing creator must list a non-zero quantity of tokens. If listing ERC-721 tokens, the listing creator must list only quantity `1`. - The listing start time must not be less than 1+ hour before the block timestamp of the transaction. The listing end time must be after the listing start time. - Only ERC-721 or ERC-1155 tokens must be listed. - The listing creator must have `LISTER_ROLE` if role restrictions are active. - The asset being listed must have `ASSET_ROLE` if role restrictions are active. ``` -------------------------------- ### Solidity `createPack` Function Signature Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/pack/pack.md This Solidity function is used to create new packs with specified contents. It requires an array of `Token` structs, the number of reward units for each token, a metadata URI for the pack, a timestamp for when opening becomes active, the amount to distribute per open, and the recipient address for the created packs. ```Solidity /// @dev Creates a pack with the stated contents. function createPack( Token[] calldata contents, uint256[] calldata numOfRewardUnits, string calldata packUri, uint128 openStartTimestamp, uint128 amountDistributedPerOpen, address recipient ) external ``` -------------------------------- ### APIDOC: MintRequest Struct Parameters Reference Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/token/signatureMint.md Detailed documentation for the fields within the `MintRequest` struct, outlining the purpose, applicability, and constraints of each parameter. This reference is essential for developers to correctly construct and interpret signature minting payloads. ```APIDOC struct MintRequest: to: The receiver of the tokens to mint. royaltyRecipient: The recipient of the minted token's secondary sales royalties. (Not applicable for ERC20 tokens) royaltyBps: The percentage of the minted token's secondary sales to take as royalties. (Not applicable for ERC20 tokens) primarySaleRecipient: The recipient of the minted token's primary sales proceeds. tokenId: The tokenId of the token to mint. (Only applicable for ERC1155 tokens) uri: The metadata URI of the token to mint. (Not applicable for ERC20 tokens) quantity: The quantity of tokens to mint. pricePerToken: The price to pay per quantity of tokens minted. (For TokenERC20, this parameter is `price`, indicating the total price of all tokens) currency: The currency in which to pay the price per token minted. validityStartTimestamp: The unix timestamp after which the payload is valid. validityEndTimestamp: The unix timestamp at which the payload expires. uid: A unique identifier for the payload. ``` -------------------------------- ### APIDOC: `PackContent` Structure Fields Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/pack/pack.md Detailed documentation for the fields comprising the `PackContent` structure, including `assetContract`, `tokenType`, `tokenId`, `totalAmount`, and `perUnitAmount`, explaining their purpose and applicability across different token standards. ```APIDOC PackContent: assetContract: The contract address of the token. tokenType: The type of the token -- ERC20 / ERC721 / ERC1155 tokenId: The tokenId of the token. (Not applicable for ERC20 tokens. The contract will ignore this value for ERC20 tokens.) totalAmount: The total amount of this token packed in the pack. (Not applicable for ERC721 tokens. The contract will always consider this as 1 for ERC721 tokens.) perUnitAmount: The amount of this token to distribute as a unit, on opening a pack. (Not applicable for ERC721 tokens. The contract will always consider this as 1 for ERC721 tokens.) ``` -------------------------------- ### Open Packs (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/pack/pack.md This Solidity function allows an owner of packs to open one or multiple packs simultaneously. Opening a pack involves burning the pack token and receiving the intended reward units from within the pack's defined contents. ```Solidity function openPack(uint256 packId, uint256 amountToOpen) external; ``` ```APIDOC openPack( packId: uint256, amountToOpen: uint256 ) external packId: The identifier of the pack to open. amountToOpen: The number of packs to open at once. ``` -------------------------------- ### Solidity Struct for Marketplace Listing Parameters Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace-legacy/marketplace.md This Solidity struct, `ListingParameters`, defines the common data structure used for creating both direct listings and auctions within the `Marketplace` smart contract. It consolidates all essential parameters such as asset contract address, token ID, timing, quantity, currency, and pricing, enabling a single `createListing` function to handle both listing types. ```solidity struct ListingParameters { address assetContract; uint256 tokenId; uint256 startTime; uint256 secondsUntilEndTime; uint256 quantityToList; address currencyToAccept; uint256 reservePricePerToken; uint256 buyoutPricePerToken; ListingType listingType; } ``` -------------------------------- ### APIDOC: ClaimConditionList Struct Parameters Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/drop/drop.md Detailed description of the parameters within the `ClaimConditionList` struct, explaining how it organizes and tracks multiple claim conditions and their associated claim data. ```APIDOC struct ClaimConditionList: currentStartId (uint256): The uid for the first claim condition amongst the current set of claim conditions. The uid for each next claim condition is one more than the previous claim condition's uid. count (uint256): The total number of claim conditions in the list of claim conditions. conditions (mapping(uint256 => ClaimCondition)): The claim conditions at a given uid. Claim conditions are ordered in an ascending order by their startTimestamp. supplyClaimedByWallet (mapping(uint256 => mapping(address => uint256))): Map from a claim condition uid and account to the supply claimed by that account. ``` -------------------------------- ### Thirdweb Marketplace: Auction Listing Parameters Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace-legacy/marketplace.md Defines the required and optional parameters for creating an NFT auction listing on the thirdweb Marketplace. These parameters control the asset, timing, quantity, accepted currency, and pricing rules for the auction. ```APIDOC AuctionListingParameters: assetContract: address # The contract address of the NFTs being listed for sale. tokenId: uint256 # The token ID on the 'assetContract' of the NFTs to list for sale. startTime: uint256 # The unix timestamp after which NFTs can be bought from the listing. secondsUntilEndTime: uint256 # No. of seconds after startTime, after which NFTs can no longer be bought from the listing. quantityToList: uint256 # The amount of NFTs of the given 'assetContract' and 'tokenId' to list for sale. For ERC721 NFTs, this is always 1. currencyToAccept: address # The address of the currency accepted by the listing. Either an ERC20 token or the chain's native token (e.g. ether on Ethereum mainnet). rerservePricePerToken: uint256 # All bids made to this auction must be at least as great as the reserve price per unit of NFTs auctioned, times the total number of NFTs put up for auction. buyoutPricePerToken: uint256 # An optional parameter. If a buyer bids an amount greater than or equal to the buyout price per unit of NFTs auctioned, times the total number of NFTs put up for auction, the auction is considered closed and the buyer wins the auctioned items. ``` -------------------------------- ### APIDOC: claim Function for Tokens Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/signature-drop/signatureDrop.md Details the `claim` function, enabling an account to claim tokens from the contract. This function requires specifying the receiver, quantity, currency, price per token, an optional allowlist proof, and arbitrary data, facilitating the token claiming process. ```APIDOC function claim( address _receiver, uint256 _quantity, address _currency, uint256 _pricePerToken, AllowlistProof calldata _allowlistProof, bytes memory _data ) public payable; Parameters: _receiver: address - Mint request in the format specified above. _quantity: uint256 - Contact owner’s signature for the mint request. _currency: address - The currency in which the price must be paid. _pricePerToken: uint256 - The price required to pay per token claimed. _allowlistProof: AllowlistProof - The proof of the claimer's inclusion in the merkle root allowlist of the claim conditions that apply. _data: bytes - Arbitrary bytes data that can be leveraged in the implementation of this interface. ``` -------------------------------- ### Marketplace Direct Listing Buy Parameters Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace-legacy/marketplace.md Parameters required by a buyer to purchase NFTs from a direct listing by paying the listing's specified fixed price on the thirdweb Marketplace. A sale requires the buyer to own or approve the Marketplace to transfer the currency, and the lister to own the NFTs and approve their transfer. ```APIDOC buyNFTsFromDirectListing( listingId: uint256, // The unique identifier of the listing to buy NFTs from. buyFor: address, // The recipient of the NFTs being bought. quantity: uint256, // The quantity of NFTs being bought from the listing. For ERC721 NFTs, this is always 1. currency: address, // The currency in which to pay for the NFTs being bought. totalPrice: uint256 // The total price to pay for the NFTs being bought. ) ``` -------------------------------- ### Marketplace Direct Listing Parameters Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace-legacy/marketplace.md Parameters required by an NFT owner (lister) to create a fixed-price direct listing for their NFTs on the thirdweb Marketplace. The listed NFTs remain in the lister's wallet until a sale is executed. ```APIDOC listNFTsForSale( assetContract: address, // The contract address of the NFTs being listed for sale. tokenId: uint256, // The token ID on the 'assetContract' of the NFTs to list for sale. startTime: uint256, // The unix timestamp after which NFTs can be bought from the listing. secondsUntilEndTime: uint256, // No. of seconds after 'startTime', after which NFTs can no longer be bought from the listing. quantityToList: uint256, // The amount of NFTs of the given 'assetContract' and 'tokenId' to list for sale. For ERC721 NFTs, this is always 1. currencyToAccept: address, // The address of the currency accepted by the listing. Either an ERC20 token or the chain's native token (e.g. ether on Ethereum mainnet). buyoutPricePerToken: uint256 // The price per unit of NFT listed for sale. ) ``` -------------------------------- ### Add Contents to an Existing Pack (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/pack/pack.md This Solidity function allows adding more tokens or assets (contents) to an already created pack. This operation is only permitted before the first transfer of packs. It requires specifying the pack ID, the array of `Token` structs representing the contents, the number of reward units for each asset, and the recipient address which must match the address used during pack creation. ```Solidity /// @dev Add contents to an existing packId. function addPackContents( uint256 packId, Token[] calldata contents, uint256[] calldata numOfRewardUnits, address recipient ) external ``` ```APIDOC addPackContents( packId: uint256, contents: Token[] calldata, numOfRewardUnits: uint256[] calldata, recipient: address ) external packId: The identifier of the pack to add contents to. contents: Tokens/assets packed in the set of pack. numOfRewardUnits: Number of reward units for each asset, where each reward unit contains per unit amount of corresponding asset. recipient: The recipient of the new supply added. Should be the same address used during creation of packs. ``` -------------------------------- ### API Documentation for mintWithSignature Function Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/token/signatureMint.md Detailed API documentation for the `mintWithSignature` function, outlining its parameters and their descriptions. This function is central to the signature minting mechanism, allowing tokens to be minted based on a verified signed request. ```APIDOC function mintWithSignature(MintRequest calldata req, bytes calldata signature) external payable; Parameters: req: The payload / mint request. signature: The signature produced by an account signing the mint request. ``` -------------------------------- ### Marketplace Direct Listing Offer Parameters Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace-legacy/marketplace.md Parameters required by a buyer to make an offer on an existing direct listing on the thirdweb Marketplace. The offer amount is not escrowed; instead, the buyer approves the Marketplace to transfer the currency upon acceptance. ```APIDOC makeOfferToDirectListing( listingId: uint256, // The unique identifier of the listing to buy NFTs from. quantityWanted: uint256, // The quantity of NFTs from the listing for which the offer is made. For ERC721 NFTs, this is always 1. pricePerToken: uint256, // The offered price per token. currency: address, // The currency in which the offer is made. expirationTimestamp: uint256 // The unix timestamp after which the offer expires. ) ``` -------------------------------- ### Retrieve a Specific NFT Offer by ID (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Fetches the detailed information of a single offer given its unique identifier. It returns a structured `Offer` object containing all relevant data about the offer. ```Solidity struct Offer { uint256 offerId; address offeror; address assetContract; uint256 tokenId; uint256 quantity; address currency; uint256 totalPrice; uint256 expirationTimestamp; TokenType tokenType; Status status; } function getOffer(uint256 offerId) external view returns (Offer memory offer); ``` ```APIDOC Parameters: offerId: The unique ID of an offer. ``` -------------------------------- ### Approve Currency for Listing (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Approves a specific currency as a valid payment method for a given listing. The caller must be the listing creator, and the approved currency must not be the primary currency of the listing. ```Solidity function approveCurrencyForListing( uint256 listingId, address currency, uint256 pricePerTokenInCurrency ) external; ``` ```APIDOC Function: approveCurrencyForListing Description: Approve a currency as a form of payment for the listing. Parameters: listingId: uint256 - The unique ID of the listing. currency: address - The address of the currency to approve as a form of payment for the listing. pricePerTokenInCurrency: uint256 - The price per token for the currency to approve. A value of 0 here disapprove a currency. Criteria that must be satisfied: - The caller of the function must be the creator of the listing in question. - The currency being approved must not be the main currency accepted by the listing. ``` -------------------------------- ### SignatureDrop Contract EIP Implementations Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/signature-drop/signatureDrop.md Outlines the Ethereum Improvement Proposals (EIPs) implemented by the SignatureDrop contract, explaining how each EIP contributes to the contract's functionality, such as token standards, royalties, and meta-transactions. ```APIDOC Relevant EIPs: EIP-721: Link: https://eips.ethereum.org/EIPS/eip-721 Relation_to_SignatureDrop: SignatureDrop is an ERC721 contract. EIP-2981: Link: https://eips.ethereum.org/EIPS/eip-2981 Relation_to_SignatureDrop: SignatureDrop implements ERC 2981 for distributing royalties for sales of the wrapped NFTs. EIP-2771: Link: https://eips.ethereum.org/EIPS/eip-2771 Relation_to_SignatureDrop: SignatureDrop implements ERC 2771 to support meta-transactions (aka “gasless” transactions). ``` -------------------------------- ### APIDOC: Internal Mappings for Claim Eligibility Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/signature-drop/signatureDrop.md Describes the internal Solidity mappings `lastClaimTimestamp` and `usedAllowlistSpot`. These mappings are used to track per-wallet claim restrictions, including the last time an account claimed tokens and whether an allowlist spot has been used for a specific claim condition. ```APIDOC /** * @dev Map from an account and uid for a claim condition, to the last timestamp * at which the account claimed tokens under that claim condition. */ mapping(bytes32 => mapping(address => uint256)) private lastClaimTimestamp; /** * @dev Map from a claim condition uid to whether an address in an allowlist * has already claimed tokens i.e. used their place in the allowlist. */ mapping(bytes32 => BitMapsUpgradeable.BitMap) private usedAllowlistSpot; Parameters: lastClaimTimestamp: mapping(bytes32 => mapping(address => uint256)) - Map from an account and uid for a claim condition, to the last timestamp at which the account claimed tokens under that claim condition. usedAllowlistSpot: mapping(bytes32 => BitMapsUpgradeable.BitMap) - Map from a uid for a claim condition to whether an address in an allowlist has already claimed tokens i.e. used their place in the allowlist. ``` -------------------------------- ### Solidity `PackContent` Structure Definition Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/pack/pack.md This Solidity struct defines the configuration for tokens within a thirdweb pack. It includes the asset contract address, token type (ERC20, ERC721, ERC1155), token ID (for ERC721/ERC1155), total amount packed, and the amount to distribute per unit when a pack is opened. ```Solidity enum TokenType { ERC20, ERC721, ERC1155 } struct Token { address assetContract; TokenType tokenType; uint256 tokenId; uint256 totalAmount; } uint256 perUnitAmount; ``` -------------------------------- ### Make an Offer for ERC721/ERC1155 NFTs (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Allows a user to create an offer for specified ERC721 or ERC1155 NFTs on the marketplace. The offer includes details such as the asset contract, token ID, quantity, currency, total price, and an expiration timestamp. The offeror must own and approve the marketplace to transfer the specified currency amount. ```Solidity struct OfferParams { address assetContract; uint256 tokenId; uint256 quantity; address currency; uint256 totalPrice; uint256 expirationTimestamp; } function makeOffer(OfferParams memory params) external returns (uint256 offerId); ``` ```APIDOC Parameters: assetContract: The contract address of the NFTs wanted. tokenId: The tokenId of the NFTs wanted. quantity: The quantity of NFTs wanted. currency: The currency offered for the NFT wanted. totalPrice: The price offered for the NFTs wanted. expirationTimestamp: The timestamp at which the offer expires. Criteria: - The offeror must own and approve Marketplace to transfer the requisite amount currency offered for the NFTs wanted. - The offeror must make an offer for non-zero quantity of NFTs. If offering for ERC721 tokens, the quantity wanted must be `1`. - Expiration timestamp must be greater than block timestamp, or within 1 hour of block timestamp. ``` -------------------------------- ### API Reference: Setting Claim Conditions in Thirdweb Drop Contracts Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/drop/drop.md This section details the parameters required when setting claim conditions in Thirdweb Drop contracts. It outlines the `conditions` array of `ClaimCondition[]` and the `resetClaimEligibility` boolean flag, explaining their purpose and impact on existing conditions and wallet eligibility. ```APIDOC setClaimConditions( conditions: ClaimCondition[], resetClaimEligibility: bool ) Parameters: - conditions: ClaimCondition[] Description: Claim conditions in ascending order by `startTimestamp`. - resetClaimEligibility: bool Description: Whether to reset `supplyClaimedByWallet` values when setting new claim conditions. ``` -------------------------------- ### Approve Buyer for Listing (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Approves a specific buyer to purchase from a reserved listing. This function can only be called by the listing creator and applies only to reserved listings. ```Solidity function approveBuyerForListing( uint256 listingId, address buyer, bool toApprove ) external; ``` ```APIDOC Function: approveBuyerForListing Description: Approve a buyer to buy from a reserved listing. Parameters: listingId: uint256 - The unique ID of the listing. buyer: address - The address of the buyer to approve to buy from the listing. toApprove: bool - Whether to approve the buyer to buy from the listing. Criteria that must be satisfied: - The caller of the function must be the creator of the listing in question. - The listing must be reserved. ``` -------------------------------- ### Reveal Delayed-Reveal NFT URI in Solidity Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/signature-drop/signatureDrop.md This function enables an account with `MINTER_ROLE` to reveal the URI for a batch of 'delayed-reveal' NFTs. It requires the batch index and a decryption key to make the metadata accessible, supporting phased NFT reveals. ```Solidity function reveal(uint256 _index, bytes calldata _key) external onlyRole(MINTER_ROLE) returns (string memory revealedURI) ``` ```APIDOC Parameters: _index: uint256 - Index of the batch for which URI is to be revealed. _key: bytes - Key for decrypting the URI. Returns: revealedURI: string - The revealed URI for the batch. ``` -------------------------------- ### APIDOC: ClaimCondition Struct Parameters Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/drop/drop.md Detailed description of the parameters within the `ClaimCondition` struct, outlining their types and purpose in defining token claim restrictions. Note that `pricePerToken` and `currency` are part of the struct but not explicitly described in the provided parameter table. ```APIDOC struct ClaimCondition: startTimestamp (uint256): The unix timestamp after which the claim condition applies. The same claim condition applies until the startTimestamp of the next claim condition. maxClaimableSupply (uint256): The maximum total number of tokens that can be claimed under the claim condition. supplyClaimed (uint256): At any given point, the number of tokens that have been claimed under the claim condition. quantityLimitPerWallet (uint256): The maximum number of tokens that can be claimed by a wallet under a given claim condition. merkleRoot (bytes32): The allowlist of addresses that can claim tokens under the claim condition. ``` -------------------------------- ### Solidity Function to Wrap Multiple Tokens into a Single NFT Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/multiwrap/multiwrap.md The `wrap` function allows a user to combine multiple ERC20, ERC721, or ERC1155 tokens into a single wrapped NFT. It requires an array of `Token` structs specifying the assets, a URI for the new NFT's metadata, and a recipient address for the newly minted wrapped NFT. This function handles the transfer of approved tokens into the contract. ```solidity function wrap( Token[] memory tokensToWrap, string calldata uriForWrappedToken, address recipient ) external payable returns (uint256 tokenId); ``` ```APIDOC function wrap(tokensToWrap: Token[], uriForWrappedToken: string, recipient: address) external payable returns (uint256 tokenId): tokensToWrap: Token[] - The tokens to wrap. uriForWrappedToken: string - The metadata URI for the wrapped NFT. recipient: address - The recipient of the wrapped NFT. ``` -------------------------------- ### Create English Auction for NFTs (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Allows users to put up ERC-721 or ERC-1155 NFTs for an English auction. This function requires a comprehensive set of parameters defining the auction's terms, including asset details, bid amounts, and time buffers. It returns a unique auction ID upon successful creation. ```APIDOC struct AuctionParameters { address assetContract; uint256 tokenId; uint256 quantity; address currency; uint256 minimumBidAmount; uint256 buyoutBidAmount; uint64 timeBufferInSeconds; uint64 bidBufferBps; uint64 startTimestamp; uint64 endTimestamp; } function createAuction(AuctionParameters memory params) external returns (uint256 auctionId); Parameters: assetContract: address - The address of the smart contract of the NFTs being auctioned. tokenId: uint256 - The tokenId of the NFTs being auctioned. quantity: uint256 - The quantity of NFTs being auctioned. This must be non-zero, and is expected to be 1 for ERC-721 NFTs. currency: address - The currency in which the bid must be made when bidding for the auctioned NFTs. minimumBidAmount: uint256 - The minimum bid amount for the auction. buyoutBidAmount: uint256 - The total bid amount for which the bidder can directly purchase the auctioned items and close the auction as a result. timeBufferInSeconds: uint64 - This is a buffer e.g. x seconds. If a new winning bid is made less than x seconds before endTimestamp, the endTimestamp is increased by x seconds. bidBufferBps: uint64 - This is a buffer in basis points e.g. x%. To be considered as a new winning bid, a bid must be at least x% greater than the current winning bid. startTimestamp: uint64 - The timestamp at and after which bids can be made to the auction. endTimestamp: uint64 - The timestamp at and after which bids cannot be made to the auction. Returns: uint256 auctionId - The unique ID of the created auction. ``` -------------------------------- ### Update Existing NFT Listing on Marketplace (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Enables modification of an existing NFT listing's details, such as price, quantity, or timestamps. Only the original creator of the listing can update it. Requires re-satisfaction of ownership and approval criteria. ```Solidity struct ListingParameters { address assetContract; uint256 tokenId; uint256 quantity; address currency; uint256 pricePerToken; uint128 startTimestamp; uint128 endTimestamp; bool reserved; } function updateListing(uint256 listingId, ListingParameters memory params) external ``` ```APIDOC Function: updateListing(uint256 listingId, ListingParameters memory params) Description: Update information (e.g. price) for one of your listings on the marketplace. Parameters: listingId (uint256): The unique ID of the listing being updated. assetContract (address): The address of the smart contract of the NFTs being listed. tokenId (uint256): The tokenId of the NFTs being listed. quantity (uint256): The quantity of NFTs being listed. This must be non-zero, and is expected to be 1 for ERC-721 NFTs. currency (address): The currency in which the price must be paid when buying the listed NFTs. The address considered for native tokens of the chain is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE pricePerToken (uint256): The price to pay per unit of NFTs listed. startTimestamp (uint128): The UNIX timestamp at and after which NFTs can be bought from the listing. endTimestamp (uint128): The UNIX timestamp at and after which NFTs cannot be bought from the listing. reserved (bool): Whether the listing is reserved to be bought from a specific set of buyers. Criteria: - The caller of the function _must_ be the creator of the listing being updated. - The listing creator must own the NFTs being listed. - The listing creator must have already approved Marketplace to transfer the NFTs being listed (since the creator is not required to escrow NFTs in the Marketplace). - The listing creator must list a non-zero quantity of tokens. If listing ERC-721 tokens, the listing creator must list only quantity `1`. - Only ERC-721 or ERC-1155 tokens must be listed. - The listing start time must be greater than or equal to the incumbent start timestamp. The listing end time must be after the listing start time. - The asset being listed must have `ASSET_ROLE` if role restrictions are active. ``` -------------------------------- ### APIDOC: Multiwrap Contract Relevant EIPs Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/multiwrap/multiwrap.md Lists the Ethereum Improvement Proposals (EIPs) that are relevant to the Multiwrap contract, explaining how each EIP relates to the contract's functionality. This includes supported token standards (ERC20, ERC721, ERC1155) and implemented features like royalties (ERC2981) and meta-transactions (ERC2771). ```APIDOC Relevant EIPs: 721: https://eips.ethereum.org/EIPS/eip-721 - Multiwrap itself is an ERC721 contract. The wrapped NFT received by a token owner on wrapping is an ERC721 NFT. Additionally, ERC721 tokens can be wrapped. 20: https://eips.ethereum.org/EIPS/eip-20 - ERC20 tokens can be wrapped. 1155: https://eips.ethereum.org/EIPS/eip-1155 - ERC1155 tokens can be wrapped. 2981: https://eips.ethereum.org/EIPS/eip-2981 - Multiwrap implements ERC 2981 for distributing royalties for sales of the wrapped NFTs. 2771: https://eips.ethereum.org/EIPS/eip-2771 - Multiwrap implements ERC 2771 to support meta-transactions (aka “gasless” transactions). ``` -------------------------------- ### Lazy Mint NFTs with Base URI in Solidity Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/signature-drop/signatureDrop.md This function allows the contract creator or an address with `MINTER_ROLE` to mint a specified amount of NFTs. It supports providing either a direct base URI for the tokens or an encrypted URI, enabling flexible metadata management for large batches. ```Solidity function lazyMint( uint256 _amount, string calldata _baseURIForTokens, bytes calldata _encryptedBaseURI ) external onlyRole(MINTER_ROLE) returns (uint256 batchId) ``` ```APIDOC Parameters: _amount: uint256 - Amount of tokens to lazy-mint. _baseURIForTokens: string - The metadata URI for the batch of tokens. _encryptedBaseURI: bytes - Encrypted URI for the batch of tokens. Returns: batchId: uint256 - The ID of the created batch. ``` -------------------------------- ### Fetch Auction Information by ID (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Retrieves detailed information about a specific auction using its unique ID. The function returns an `Auction` struct, which contains all relevant data points for an auction. ```solidity struct Auction { uint256 auctionId; address auctionCreator; address assetContract; uint256 tokenId; uint256 quantity; address currency; uint256 minimumBidAmount; uint256 buyoutBidAmount; uint64 timeBufferInSeconds; uint64 bidBufferBps; uint64 startTimestamp; uint64 endTimestamp; TokenType tokenType; Status status; } function getAuction(uint256 auctionId) external view returns (Auction memory auction); ``` ```APIDOC struct Auction { uint256 auctionId; address auctionCreator; address assetContract; uint256 tokenId; uint256 quantity; address currency; uint256 minimumBidAmount; uint256 buyoutBidAmount; uint64 timeBufferInSeconds; uint64 bidBufferBps; uint64 startTimestamp; uint64 endTimestamp; TokenType tokenType; Status status; } getAuction(auctionId: uint256) external view returns (Auction memory auction) auctionId: uint256 - The unique ID of the auction. ``` -------------------------------- ### Solidity: Claim Eligibility Check Pseudo-code Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/drop/drop.md This Solidity pseudo-code snippet illustrates the core logic for checking a wallet's claim eligibility against a specific claim condition. It retrieves the `supplyClaimedByWallet` for the current condition and ensures that the `quantityToClaim` does not exceed the `quantityLimitPerWallet` when combined with already claimed tokens. ```Solidity // pseudo-code supplyClaimedByWallet = claimCondition.supplyClaimedByWallet[conditionId][claimer]; require(quantityToClaim + supplyClaimedByWallet <= quantityLimitPerWallet); ``` -------------------------------- ### Bid In Auction (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md This function allows a user to make a bid in an ongoing auction. It is a payable function, meaning it can receive Ether or native tokens. Several conditions must be met, including the auction not being expired, the caller owning and approving the Marketplace to transfer the bid amount, and the bid being a new winning bid. ```solidity function bidInAuction(uint256 auctionId, uint256 bidAmount) external payable; ``` ```APIDOC bidInAuction(auctionId: uint256, bidAmount: uint256) external payable auctionId: uint256 - The unique ID of the auction to bid in. bidAmount: uint256 - The total bid amount. Criteria: - Auction must not be expired. - The caller must own and approve Marketplace to transfer the requisite bid amount to itself. - The bid amount must be a winning bid amount. (For convenience, this can be verified by calling `isNewWinningBid`) ``` -------------------------------- ### Retrieve All Valid Offers within a Range (Solidity) Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/marketplace/marketplace-v3.md Returns an array of offers within a specified ID range that are currently considered valid. A valid offer is one that is active, and for which the offeror still owns and has approved the marketplace to transfer the currency tokens. ```Solidity function getAllValidOffer(uint256 startId, uint256 endId) external view returns (Offer[] memory offers); ``` ```APIDOC Parameters: startId: Inclusive start offer Id. endId: Inclusive end offer Id. ``` -------------------------------- ### Calculate Random Number for Delayed-Reveal Pack Opening Source: https://github.com/thirdweb-dev/contracts/blob/main/contracts/prebuilts/pack/pack.md This Solidity code snippet demonstrates how a random number would be calculated in a proposed 'delayed-reveal' randomness scheme. It uses the `keccak256` hash function, combining a creator-provided `seed`, the `msg.sender` (pack opener's address), and the `blockhash` of a `storedBlockNumber` to generate a pseudo-random `uint256`. This approach aims to prevent prediction and manipulation by ensuring the `seed` is fixed and packs are non-transferrable. ```solidity uint256 random = uint(keccak256(seed, msg.sender, blockhash(storedBlockNumber))); ```