Use case: Marketplace
This page outlines how developers can use the Unreal Engine zkEVM API module to display active listings.
This can be useful for managing the players NFT stacks which are for sale in your in-game marketplace.
This can be useful for managing the players NFT stacks which are for sale in your in-game marketplace.
💡Who is this for?
Developers who want to use the zkEVM API in Unreal.
Overview
Displaying a player's active NFT listings is a common requirement of an in-game marketplace.
To do this, you can simply send a request to the Immutable zkEVM API to fetch the NFTs owned by a player using the OnlyIfHasActiveListings
flag and
then processing the request to display the NFTs in your in-game marketplace.
Displaying NFT stacks in the game marketplace
To display NFT stacks, you can use the Search NFT Stacks endpoint, which retrieves stacks of NFTs grouped by their metadata attributes.
Obtain NFT marketplace stacks using the zkEVM API
ImmutableOpenAPI::OpenAPIStacksApi::SearchStacksRequest SearchStacksRequest;
SearchStacksRequest.PageSize = (ListPanel->GetNumberOfColumns() * ListPanel->GetNumberOfRows());
SearchStacksRequest.PageCursor = PageCursor;
SearchStacksRequest.AccountAddress = GetOwningCustomLocalPLayer()->GetPassportWalletAddress();
SearchStacksRequest.ContractAddress = Policy->GetContracts();
SearchStacksRequest.ChainName = Policy->GetChainName();
SearchStacksRequest.OnlyIfHasActiveListings = true;
HandleSorting(SearchStacksRequest.SortBy);
if (!Policy->GetKeyword().IsEmpty())
{
SearchStacksRequest.Keyword = Policy->GetKeyword();
}
if (!Policy->GetTraits().IsEmpty())
{
SearchStacksRequest.Trait = Policy->GetTraits();
}
Policy->GetStacksAPI()->SearchStacks(SearchStacksRequest, ImmutableOpenAPI::OpenAPIStacksApi::FSearchStacksDelegate::CreateUObject(this, &USearchStacksWidget::OnSearchStacksResponse));
Example of processing the response
void USearchStacksWidget::OnSearchStacksResponse(const ImmutableOpenAPI::OpenAPIStacksApi::SearchStacksResponse& Response)
{
...
int32 NumberOfResults = Response.Content.Result.Num();
...
for (int32 ResultId = 0; ResultId < NumberOfResults; ResultId++)
{
if (auto ItemWidget = Cast<IMarketplaceOpenAPIProcessorInterface>(ListPanel->GetItem(Column, Row)))
{
ItemWidget->ProcessModel(Response.Content.Result[ResultId]);
}
if (auto ItemWidget = ListPanel->GetItem(Column, Row))
{
ItemWidget->RegisterOnSelectionChange(UItemWidget::FOnSelectionChange::CreateUObject(this, &USearchStacksWidget::OnItemSelectionChange));
ItemWidget->RegisterOnDoubleClick(UItemWidget::FOnDoubleClick::CreateUObject(this, &USearchStacksWidget::OnItemDoubleClick));
}
}
}
Example in-game marketplace
You can view a full example of an in-game marketplace in the sample game here, which also utilises the Search Stacks endpoint.
Related content
zkEVM APIs
Find out more information on what's available through the APIs and how to use them.
Learn more
Unreal SDK Reference
For more information on all the available methods in our Unreal SDK, check out the SDK Reference.
Learn more
Unreal Marketplace Tutorial
This tutorial series walks you through the in-game marketplace in our Unreal sample game.
Learn more