When listing an item on Solana from a backend, use the listItem helper method to call the listVirtual or listNft based on whether the item id is a mint pubkey or virtual id.
awaitcarbon.methods.listItem({ itemId, collectionMint, price: lamports, expiry // unix timestamp or 0 if no expiration})
Frontend
Listing Virtual Items
Since the marketplace authority needs to validate any virtual items being listed, the listVirtual method requires a signature from the marketplace authority. The transactions.listVirtual method can be used to generate a signed transaction to be sent back to the seller for their signature.
// ...User requests a list virtual transaction// BackendconstsignedTx=awaitcarbon.transactions.listVirtual({ seller, itemId, collectionMint, price, expiry,})constresponseBody= { tx:signedTx.serialize({// Seller still needs to sign requireAllSignatures:false, verifySignatures:false }).toString('base64'),}// ...Send responseBody back to seller for signature// Frontendconsttx=Transaction.from(Buffer.from(responseBody.tx,'base64'));constsignedTx=awaitanchorWallet.signTransaction(tx)constserialized=signedTx.serialize()constsignature=awaitconn.sendRawTransaction(serialized)
Listing NFTs
When listing an item that's already been minted as an NFT, it's much more straightforward.
// It's convenient to use metaplex to fetch the collection address if neededconstnft=awaitmetaplex.nfts().findByMint({ mintAddress,})awaitcarbon.methods.listNft({ seller: anchorWallet, mint: mintAddress, collectionMint:nft.collection!.address, price: lamports, expiry,// unix timestamp or 0 if no expiration})