Skip to main content

Cancel orders

Once an order has been listed, it can be canceled if the player no longer wants to sell their NFT.

An order can only be cancelled before it has been filled by another player.
Unreal OrderbookUnreal Orderbook
💡Who is this for?
Developers who want to build an in-game marketplace in Unreal.
💡Alpha version
This module is experimental and may change in the future. We recommend using it for testing purposes only.

Overview

To cancel an order, the player needs to sign a cancel order transaction that includes the listing ID of the order they are wanting to cancel and the seller's wallet address.

To list cancel a listing, you need to do the following:

  1. Prepare the cancel order.
  2. Submit the cancel order.

Below are partial code snippets that demonstrate the essential parts of each of these steps. If you want to see the full implementation, you can take a look at SearchNFTsWidget.cpp in our Unreal sample game and the Build a marketplace in Unreal tutorial.

Cancel order workflow

1. Prepare the cancel order

This step sets up the necessary data for a cancelling an order, including the the order's ID and the seller's wallet address, and then sends the request using CancelOrdersOnChain method of Immutable Orderbook API.

ImmutableTsSdkApi::OpenAPIOrderbookApi::CancelOrdersOnChainRequest Request;
ImmutableTsSdkApi::OpenAPICancelOrdersOnChainRequest RequestData;

RequestData.AccountAddress = LocalPlayer->GetPassportWalletAddress();
RequestData.OrderIds.AddUnique(SelectedItemWidget->GetListingId());

Request.OpenAPICancelOrdersOnChainRequest = RequestData;

Policy->GetTsSdkAPI()->CancelOrdersOnChain(Request, ImmutableTsSdkApi::OpenAPIOrderbookApi::FCancelOrdersOnChainDelegate::CreateUObject(this, &USearchNfTsWidget::OnCancelOrdersOnChain));

2. Submit the cancel order

Unlike creating or filling an order, it's assumed the player already has approved your collection to interact with the Immutable Orderbook to create their listing, so you don't need to sign and submit an approval transaction.

You only need to sign and submit the cancel order transaction as shown below.

void USearchNfTsWidget::OnCancelOrdersOnChain(const ImmutableOrderbook::APIOrderbookApi::CancelOrdersOnChainResponse& Response)
{
...
ImmutableOrderbook::APICancelOrdersOnChain200Response OkResponse;
TSharedPtr<FJsonValue> JsonValue;

FJsonSerializer::Deserialize(TJsonReaderFactory<>::Create(Response.GetHttpResponse()->GetContentAsString()), JsonValue);

...

OkResponse.FromJson(JsonValue);

...

auto Action = OkResponse.CancellationAction.GetValue();
FString PopulatedTransactionsTo = Action.PopulatedTransactions.GetValue().To.GetValue();
FString PopulatedTransactionsData = Action.PopulatedTransactions.GetValue().Data.GetValue();

GetOwningCustomLocalPLayer()->SignSubmitApproval(PopulatedTransactionsTo, PopulatedTransactionsData, [this](FString TransactionHash, FString Status)
{
...
});
}

After cancelling the order

The order cancellation transaction is now being processed. Upon validating the required the ownership of the listing being cancelled onchain, the order will asynchronously transition to the CANCELLED status.

We recommend taking an optimistic view and showing the order as CANCELLED as soon as it is submitted, then polling the order status to check for updates for the most seamless player experience.

💡Status polling
You can poll the Get Listing endpoint to check on status updates. - in the near future we also plan on introducing push based (webhook) integration for order events.

You can see all the different order status types in the table in the order statuses documentation.

For more details on each step, you can read the Typescript documentation for cancelling orders since the Unreal Orderbook closely follows this implementation. You can also view a full example in the Unreal sample game.


Related content