Skip to main content

useAcceptDirectListingOffer

Hook for accepting an offer from a direct listing on a Marketplace contract.

Allows the seller (the user who listed the NFT for sale) to accept an offer on their listing, triggering a sale event, meaning the:

  • NFT(s) are transferred from the seller to the buyer.
  • Funds from the offeror are sent to the seller.
import { useAcceptDirectListingOffer } from "@thirdweb-dev/react";

Usage

Provide a Marketplace contract instance from the useContract hook as the first argument.

import {
useAcceptDirectListingOffer,
useContract,
Web3Button,
} from "@thirdweb-dev/react";

// Your smart contract address
const contractAddress = "{{contract_address}}";

function App() {
const { contract } = useContract(contractAddress, "marketplace");
const {
mutateAsync: acceptDirectOffer,
isLoading,
error,
} = useAcceptDirectListingOffer(contract);

return (
<Web3Button
contractAddress={contractAddress}
action={() =>
acceptDirectOffer({
listingId: "{{listing_id}}",
addressOfOfferor: "{{offeror_address}}",
})
}
>
Accept Offer
</Web3Button>
);
}

Configuration

listingId (required)

The listingId of the listing you wish to accept.

Each listing has a unique listingId on the marketplace contract.

import {
useAcceptDirectListingOffer,
useContract,
Web3Button,
} from "@thirdweb-dev/react";

// Your smart contract address
const contractAddress = "{{contract_address}}";

function App() {
const { contract } = useContract(contractAddress, "marketplace");
const {
mutateAsync: acceptDirectOffer,
isLoading,
error,
} = useAcceptDirectListingOffer(contract);

return (
<Web3Button
contractAddress={contractAddress}
action={() =>
acceptDirectOffer({
listingId: "{{listing_id}}",
addressOfOfferor: "{{offeror_address}}",
})
}
>
Accept Offer
</Web3Button>
);
}

addressOfOfferor (required)

The wallet address of the user who made the offer you wish to accept.

The useContractEvents hook can be used to read all NewOffer events on your marketplace contract.

import {
useAcceptDirectListingOffer,
useContract,
Web3Button,
} from "@thirdweb-dev/react";

// Your smart contract address
const contractAddress = "{{contract_address}}";

function App() {
const { contract } = useContract(contractAddress, "marketplace");
const {
mutateAsync: acceptDirectOffer,
isLoading,
error,
} = useAcceptDirectListingOffer(contract);

return (
<Web3Button
contractAddress={contractAddress}
action={() =>
acceptDirectOffer({
listingId: "{{listing_id}}",
addressOfOfferor: "{{offeror_address}}",
})
}
>
Accept Offer
</Web3Button>
);
}