useCreateDirectListing
Hook for creating a new direct listing on a Marketplace or MarketplaceV3 smart contract.
Direct listings require the user to approve the marketplace to transfer the NFTs on their behalf as part of the listing creation process. This is because the marketplace needs permission to execute sales and transfer the NFTs to the buyer when a sale is made.
import { useCreateDirectListing } from "@thirdweb-dev/react";
const { mutateAsync, isLoading, error } = useCreateDirectListing(contract);
Usage
Provide your marketplace contract as the argument.
Then, provide the information about the listing you want to create as the argument to the mutation.
import {
useCreateDirectListing,
useContract,
Web3Button,
} from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const { contract } = useContract(contractAddress, "marketplace-v3");
const {
mutateAsync: createDirectListing,
isLoading,
error,
} = useCreateDirectListing(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
createDirectListing({
assetContractAddress: "{{asset_contract_address}}",
tokenId: "{{token_id}}",
pricePerToken: "{{price_per_token}}",
currencyContractAddress: "{{currency_contract_address}}",
isReservedListing: false,
quantity: "{{quantity}}",
startTimestamp: new Date(),
endTimestamp: new Date(
new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
),
})
}
>
Create Direct Listing
</Web3Button>
);
}