Save listing is part of the create listing process. create-listing end point returns a psbt which is signed by the client wallet, once signed the signed psbt needs to be saved in the listing database by calling /save-listing end point.
Here's an example of how you can sign a listing transaction with the Xverse wallet and then save it by calling /save-listing:
// XVerse Wallet example of creating a signing request
// when listing an Ordinal for sale
const sellerInput = {
address: ordinalsAddress, // Seller's ordinal wallet address
signingIndexes: [0], // always [0] when listing
// Specify sigHash type as SIGHASH_SINGLE | SIGHASH_ANYONECANPAY
sigHash: bitcoin.Transaction.SIGHASH_SINGLE | bitcoin.Transaction.SIGHASH_ANYONECANPAY,
};
// Create the listing PSBT by calling /marketplace/create-listing API
// This returns a base64 PSBT in string format which needs to be signed
const { data } = await axios({
method: 'post'
url: 'https://api.ordinalsbot.com/marketplace/create-listing',
data: {
sellerOrdinals
sellerPaymentAddress,
sellerOrdinalPublicKey
},
headers: {
'x-api-key': API_KEY,
});
// When using XVerse Wallet
// Create the payload for signing the seller transaction
const payload = {
network: { type: "Mainnet" },
message: "Sign Seller Transaction",
psbtBase64: data.psbt, // PSBT returned by the clear-listing API
broadcast: false,
inputsToSign: [sellerInput],
};
// Make signing request
await signTransaction({
payload,
onFinish: async (response) => {
try {
// signed succesffully
// Save the listing with the signed PSBT
const updateListingData = {
signedListingPSBT: response.psbtBase64,
};
// Save the listing PSBT by calling /marketplace/save-listing API
// This returns a base64 PSBT in string format which needs to be signed
const saveResponse= await axios({
method: 'patch'
url: 'https://api.ordinalsbot.com/marketplace/save-listing' + sellerOrdinals[0].id,
data: {
sellerOrdinals: [sellerOrdinals[0].id],
updateListingData
},
headers: {
'x-api-key': API_KEY,
}
});
} catch (Error) {
// error handling
}
},
onCancel: () => { // User cancelled signing request }
});