List and manage NFTs on Tensor Trade
// List NFT const signature = await agent.methods.tensorListNFT( new PublicKey("nft-mint-address"), 1.5 // Price in SOL );
// Cancel listing const signature = await agent.methods.tensorCancelListing( new PublicKey("nft-mint-address") );
"List my NFT for 2 SOL on Tensor" "Cancel my NFT listing on Tensor" "Put NFT up for sale at 1.5 SOL" "Remove NFT listing from marketplace"
{ "nftMint": "nft-mint-address", "price": 1.5 }
{ "nftMint": "nft-mint-address" }
interface ListingParams { nftMint: PublicKey; // NFT mint address nftSource: PublicKey; // Token account owner: PublicKey; // Owner address price: BN; // Price in lamports tokenProgram: PublicKey; // Token program ID payer: PublicKey; // Transaction payer } // Price conversion const priceInLamports = new BN(price * 1e9);
// Get Associated Token Account const ata = await getAssociatedTokenAddress( nftMint, ownerAddress ); // Verify ownership const tokenAccount = await getAccount( connection, ata ); if (!tokenAccount || tokenAccount.amount <= 0) { throw new Error("NFT not owned"); }
try { const tx = await agent.methods.tensorListNFT(mint, price); } catch (error) { if (error.message.includes("NFT not found")) { // Handle missing NFT } else if (error.message.includes("Invalid mint")) { // Handle invalid address } }
{ status: "success", message: "NFT listed successfully", transaction: "transaction-signature", price: 1.5, nftMint: "mint-address" }
{ status: "error", message: "Error message", code: "ERROR_CODE" }
const provider = new AnchorProvider( connection, wallet, AnchorProvider.defaultOptions() ); const tensorSwapSdk = new TensorSwapSDK({ provider });
// Build transaction const { tx } = await tensorSwapSdk.list(params); // Create and send transaction const transaction = new Transaction(); transaction.add(...tx.ixs); return await connection.sendTransaction( transaction, [wallet, ...tx.extraSigners] );
Was this page helpful?