useOffers

Hook for getting all of the offers made on a direct listing on a Marketplace contract.

Example

import { useOffers, useContract } from "@thirdweb-dev/react";
function App() {
const { contract } = useContract(contractAddress, "marketplace");
const {
data: offers,
isLoading,
error,
} = useOffers(contract, listingId);
}
function useOffers(
contract: RequiredParam<Marketplace>,
listingId: RequiredParam<BigNumberish>,
):
| {
data: undefined | Array<Record<string, any>>;
dataUpdatedAt: number;
error: unknown;
errorUpdateCount: number;
errorUpdatedAt: number;
failureCount: number;
failureReason: unknown;
fetchStatus: FetchStatus;
isError: true;
isFetched: boolean;
isFetchedAfterMount: boolean;
isFetching: boolean;
isInitialLoading: boolean;
isLoading: false;
isLoadingError: false;
isPaused: boolean;
isPlaceholderData: boolean;
isPreviousData: boolean;
isRefetchError: true;
isRefetching: boolean;
isStale: boolean;
isSuccess: false;
refetch: (
options?: RefetchOptions & RefetchQueryFilters<TPageData>,
) => Promise<
QueryObserverResult<
Array<ContractEvent<Record<string, any>>>,
unknown
>
>;
remove: () => void;
status: "error";
}
| {
data: undefined | Array<Record<string, any>>;
dataUpdatedAt: number;
error: null;
errorUpdateCount: number;
errorUpdatedAt: number;
failureCount: number;
failureReason: unknown;
fetchStatus: FetchStatus;
isError: false;
isFetched: boolean;
isFetchedAfterMount: boolean;
isFetching: boolean;
isInitialLoading: boolean;
isLoading: false;
isLoadingError: false;
isPaused: boolean;
isPlaceholderData: boolean;
isPreviousData: boolean;
isRefetchError: false;
isRefetching: boolean;
isStale: boolean;
isSuccess: true;
refetch: (
options?: RefetchOptions & RefetchQueryFilters<TPageData>,
) => Promise<
QueryObserverResult<
Array<ContractEvent<Record<string, any>>>,
unknown
>
>;
remove: () => void;
status: "success";
}
| {
data: undefined | Array<Record<string, any>>;
dataUpdatedAt: number;
error: unknown;
errorUpdateCount: number;
errorUpdatedAt: number;
failureCount: number;
failureReason: unknown;
fetchStatus: FetchStatus;
isError: true;
isFetched: boolean;
isFetchedAfterMount: boolean;
isFetching: boolean;
isInitialLoading: boolean;
isLoading: false;
isLoadingError: true;
isPaused: boolean;
isPlaceholderData: boolean;
isPreviousData: boolean;
isRefetchError: false;
isRefetching: boolean;
isStale: boolean;
isSuccess: false;
refetch: (
options?: RefetchOptions & RefetchQueryFilters<TPageData>,
) => Promise<
QueryObserverResult<
Array<ContractEvent<Record<string, any>>>,
unknown
>
>;
remove: () => void;
status: "error";
}
| {
data: undefined | Array<Record<string, any>>;
dataUpdatedAt: number;
error: null;
errorUpdateCount: number;
errorUpdatedAt: number;
failureCount: number;
failureReason: unknown;
fetchStatus: FetchStatus;
isError: false;
isFetched: boolean;
isFetchedAfterMount: boolean;
isFetching: boolean;
isInitialLoading: boolean;
isLoading: true;
isLoadingError: false;
isPaused: boolean;
isPlaceholderData: boolean;
isPreviousData: boolean;
isRefetchError: false;
isRefetching: boolean;
isStale: boolean;
isSuccess: false;
refetch: (
options?: RefetchOptions & RefetchQueryFilters<TPageData>,
) => Promise<
QueryObserverResult<
Array<ContractEvent<Record<string, any>>>,
unknown
>
>;
remove: () => void;
status: "loading";
};

Parameters

Instance of a Marketplace contract

Type

let contract: RequiredParam<Marketplace>;

The id of the listing to fetch offers for If the listing cannot be found, is not a direct listing, or is not active, the error property will be set.

Type

let listingId: RequiredParam<BigNumberish>;

Returns

let returnType:
| {
data: undefined | Array<Record<string, any>>;
dataUpdatedAt: number;
error: unknown;
errorUpdateCount: number;
errorUpdatedAt: number;
failureCount: number;
failureReason: unknown;
fetchStatus: FetchStatus;
isError: true;
isFetched: boolean;
isFetchedAfterMount: boolean;
isFetching: boolean;
isInitialLoading: boolean;
isLoading: false;
isLoadingError: false;
isPaused: boolean;
isPlaceholderData: boolean;
isPreviousData: boolean;
isRefetchError: true;
isRefetching: boolean;
isStale: boolean;
isSuccess: false;
refetch: (
options?: RefetchOptions & RefetchQueryFilters<TPageData>,
) => Promise<
QueryObserverResult<
Array<ContractEvent<Record<string, any>>>,
unknown
>
>;
remove: () => void;
status: "error";
}
| {
data: undefined | Array<Record<string, any>>;
dataUpdatedAt: number;
error: null;
errorUpdateCount: number;
errorUpdatedAt: number;
failureCount: number;
failureReason: unknown;
fetchStatus: FetchStatus;
isError: false;
isFetched: boolean;
isFetchedAfterMount: boolean;
isFetching: boolean;
isInitialLoading: boolean;
isLoading: false;
isLoadingError: false;
isPaused: boolean;
isPlaceholderData: boolean;
isPreviousData: boolean;
isRefetchError: false;
isRefetching: boolean;
isStale: boolean;
isSuccess: true;
refetch: (
options?: RefetchOptions & RefetchQueryFilters<TPageData>,
) => Promise<
QueryObserverResult<
Array<ContractEvent<Record<string, any>>>,
unknown
>
>;
remove: () => void;
status: "success";
}
| {
data: undefined | Array<Record<string, any>>;
dataUpdatedAt: number;
error: unknown;
errorUpdateCount: number;
errorUpdatedAt: number;
failureCount: number;
failureReason: unknown;
fetchStatus: FetchStatus;
isError: true;
isFetched: boolean;
isFetchedAfterMount: boolean;
isFetching: boolean;
isInitialLoading: boolean;
isLoading: false;
isLoadingError: true;
isPaused: boolean;
isPlaceholderData: boolean;
isPreviousData: boolean;
isRefetchError: false;
isRefetching: boolean;
isStale: boolean;
isSuccess: false;
refetch: (
options?: RefetchOptions & RefetchQueryFilters<TPageData>,
) => Promise<
QueryObserverResult<
Array<ContractEvent<Record<string, any>>>,
unknown
>
>;
remove: () => void;
status: "error";
}
| {
data: undefined | Array<Record<string, any>>;
dataUpdatedAt: number;
error: null;
errorUpdateCount: number;
errorUpdatedAt: number;
failureCount: number;
failureReason: unknown;
fetchStatus: FetchStatus;
isError: false;
isFetched: boolean;
isFetchedAfterMount: boolean;
isFetching: boolean;
isInitialLoading: boolean;
isLoading: true;
isLoadingError: false;
isPaused: boolean;
isPlaceholderData: boolean;
isPreviousData: boolean;
isRefetchError: false;
isRefetching: boolean;
isStale: boolean;
isSuccess: false;
refetch: (
options?: RefetchOptions & RefetchQueryFilters<TPageData>,
) => Promise<
QueryObserverResult<
Array<ContractEvent<Record<string, any>>>,
unknown
>
>;
remove: () => void;
status: "loading";
};

This hook uses the useEvents hook under the hood to fetch NewOffer events for the given listing ID.

The return value is an array of NewOffer event objects. Each event object has the following properties:

{
offeror: string;
offerId: BigNumber;
assetContract: string;
offer: {
offerId: BigNumber;
offeror: string;
assetContract: string;
tokenId: BigNumber;
quantity: BigNumber;
currency: string;
totalPrice: BigNumber;
expirationTimestamp: BigNumber;
tokenType: "ERC721" | "ERC1155";
status: "UNSET" | "CREATED" | "COMPLETED" | "CANCELLED";
}
}