useCancelListing

Hook for canceling an existing auction or listing on a Marketplace contract.

Auction listings cannot be canceled if a bid has been placed

This hook is only for Marketplace contracts.

For Marketplace V3 contracts, use useCancelDirectListing or useCancelEnglishAuction instead.

Example

import {
useCancelListing,
useContract,
Web3Button,
} from "@thirdweb-dev/react";
import { ListingType } from "@thirdweb-dev/sdk";
function App() {
const { contract } = useContract(contractAddress, "marketplace");
const {
mutateAsync: cancelListing,
isLoading,
error,
} = useCancelListing(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
cancelListing({
id: "{{listing_id}}",
type: ListingType.Direct, // Direct (0) or Auction (1)
})
}
>
Cancel Listing
</Web3Button>
);
}

Parameters

Returns

Mutation object to cancel a listing.

const { mutateAsync, isLoading, error } = useCancelListing(contract);

The error property is set if the listing is not active, or was not created by the wallet.

options

The mutation function takes an object with the following properties as an argument:

listingId

The ID of the listing you want to cancel.

listingType

The type of listing you are canceling. Either ListingType.Direct (0) or ListingType.Auction (1).