Listing Items

Backend

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.

await carbon.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

// Backend
const signedTx = await carbon.transactions.listVirtual({
  seller,
  itemId,
  collectionMint,
  price,
  expiry,
})

const responseBody = {
  tx: signedTx.serialize({
    // Seller still needs to sign
    requireAllSignatures: false,
    verifySignatures: false
  }).toString('base64'),
}

// ...Send responseBody back to seller for signature

// Frontend
const tx = Transaction.from(Buffer.from(responseBody.tx, 'base64'));
const signedTx = await anchorWallet.signTransaction(tx)
const serialized = signedTx.serialize()
const signature = await conn.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 needed
const nft = await metaplex.nfts().findByMint({
    mintAddress,
})

await carbon.methods.listNft({
    seller: anchorWallet,
    mint: mintAddress,
    collectionMint: nft.collection!.address,
    price: lamports,
    expiry, // unix timestamp or 0 if no expiration
})

Last updated