Listing prices will be returned in USD, which the game is responsible for converting to price in virtual currency using the known rate of their virtual currency to USD.
Buy a listed item
When the player selects a listing they'd like to purchase, we can call the /purchase endpoint on the listing.
// The id of the listing the player selected to purchase
const listingId = "068e3ff0-5db2-41dc-9b14-a3a0dce108e5"
// Construct details of the purchase
const purchaseDetails = {
"playerId": "f4e5d3a4-2a9b-4d9f-bc5a-73b3f0c47b5e", // The player purchasing the listing
"version": 1, // The version of the listing, to ensure it hasn't changed
"mythToUSD": 0.33 // Will be checked to see if rate has deviated too far since listing was viewed
}
// The players VC will be deducted and the marketplace purchase will occur
const purchaseRespose = await fetch(`/v1/listings/${listingId}/purchase`, {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(purchaseDetails),
});
// Successful response means the purchase is initiated
const { traceId } = await purchaseRespose.json();
// TraceId can be fetched to check state
const traceResponse = await fetch('/trace/{id}', {
method: 'GET',
headers: {},
});
const { state } = await traceResponse.json();
// Handle state
switch(state) {
// ...
}