# Example 2: NFT Marketplace / Platform

**Scenario:** An NFT platform where users can list NFTs for sale, browse available NFTs, and purchase them – all on Solana.

**Prompt Example:**

```markdown
markdownKopierenBearbeitenYou are a Solana blockchain and front-end expert. 

**Task:** Create a **Solana NFT marketplace dApp**. 

**Requirements:**
- **Solana Program (Rust/Anchor):** Write an Anchor program for an NFT marketplace. It should allow users to list an NFT for sale by specifying a price, and allow another user to buy it. Use the Metaplex token metadata standard for NFTs (i.e., ensure the program checks the NFT’s metadata/owner). Include instructions: `list_nft(token_account, price)`, `buy_nft(token_account)`. The `list_nft` instruction should create a listing (perhaps a PDA account for the listing with price, seller pubkey, NFT mint, etc.), and transfer the NFT to escrow (the program) or use a escrow token account. The `buy_nft` instruction should transfer SOL from buyer to seller and return the NFT to the buyer. Include safety checks: only the NFT owner can list, only one listing per NFT at a time, etc.
- **Front-End (React/TypeScript):** Build a web UI where users can connect their Solana wallet to view listed NFTs and their details (image, price, seller). Provide a form to list an NFT (the user inputs the NFT mint address and price, then calls `list_nft`). Also provide a "Buy" button on each listed NFT that triggers the `buy_nft` transaction. Use @solana/web3.js or Anchor’s provider to interact with the program. Update the UI state after transactions (e.g., remove sold items, show the NFT in the buyer’s collection).
- **Integration:** Use a library or SDK to fetch NFT metadata for displaying images/name (for example, integrate with Metaplex JS SDK or Solana RPC calls to get metadata URI). 
- **Comments & UX:** Comment the Rust code to explain account layouts (especially the listing PDA structure). In the front-end code, add comments where you integrate with Solana (e.g., when sending a transaction). Ensure the UI has error handling (e.g., if a transaction fails or if user doesn’t have enough SOL). Format the output as two code sections: Anchor program and front-end.
```

This prompt is more complex, but it shows how to instruct the AI to handle a realistic scenario. Key points:

* We explicitly reference **Metaplex token metadata** and typical marketplace behavior. This nudges the AI to use existing standards and best practices for NFTs on Solana, rather than something made-up. (This is an example of leveraging context: even if the AI isn’t perfectly aware of Metaplex, mentioning it will shape its output logic appropriately.)
* We outlined the program’s instruction set and data (listing with price, etc.), which gives the AI a scaffold to implement.
* We also outlined front-end features like displaying images and integrating wallet – this ensures the AI-generated UI isn’t bare-bones but actually does the important stuff (like showing NFT details).
* The inclusion of **comments and error handling** again reinforces quality.

After getting an output from such a prompt, you would definitely need to review things: e.g., does the program properly use the token program to transfer NFTs? Are there security checks on who can call `buy_nft`? The prompt’s clarity should lead the AI to cover much of this, but as always you refine as needed. You might do this dApp in stages (first just listing, then buying logic, then UI) if the initial attempt misses something.
