Web3 & DApp Development Fundamentals · レッスン

マーケットプレイス

出品と転送

レッスン 4/413 ステップ

「マーケットプレイス」はCoddyKit上の無料Web3 & DApp Development Fundamentalsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWeb3 & DApp Development Fundamentals学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Web3 & DApp Development Fundamentalsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

How NFT Marketplaces Work

An NFT marketplace lets users list tokens for sale and lets buyers purchase them. Behind the scenes it relies on the ERC-721 approval and transfer mechanics you have already learned.

The marketplace contract never owns your NFT - it just moves it when a sale executes.

The Approval Step

Before listing, the seller must approve the marketplace to move the token. Sellers usually call setApprovalForAll so one approval covers all their NFTs in a collection.

<code>// seller authorizes the marketplace
nft.setApprovalForAll(marketplaceAddress, true);</code>

Storing a Listing

The marketplace records each listing with the seller, the NFT contract, the token id, and the price.

<code>struct Listing {
    address seller;
    address nft;
    uint256 tokenId;
    uint256 price;
}
mapping(bytes32 => Listing) public listings;</code>

Creating a Listing

To list, the seller calls a function that verifies they own the token and that the marketplace is approved, then stores the listing.

<code>function list(address nft, uint256 tokenId, uint256 price) public {
    require(IERC721(nft).ownerOf(tokenId) == msg.sender, 'not owner');
    require(IERC721(nft).isApprovedForAll(msg.sender, address(this)), 'not approved');
    bytes32 id = keccak256(abi.encodePacked(nft, tokenId));
    listings[id] = Listing(msg.sender, nft, tokenId, price);
}</code>

Buying an NFT

A buyer sends the price as Ether. The marketplace transfers the NFT from seller to buyer using safeTransferFrom and forwards the payment.

<code>function buy(bytes32 id) public payable {
    Listing memory l = listings[id];
    require(msg.value >= l.price, 'insufficient payment');
    delete listings[id];
    IERC721(l.nft).safeTransferFrom(l.seller, msg.sender, l.tokenId);
    payable(l.seller).transfer(l.price);
}</code>

Delete Before Transfer

Notice the listing is deleted before external calls. This follows the checks-effects-interactions pattern and prevents reentrancy from buying the same NFT twice.

<code>delete listings[id]; // effect first
// then interactions (transfers)</code>

Marketplace Fees

Marketplaces typically take a percentage fee. The contract splits the payment between the seller and a fee recipient.

<code>uint256 public feeBps = 250; // 2.5%

uint256 fee = (l.price * feeBps) / 10000;
payable(feeRecipient).transfer(fee);
payable(l.seller).transfer(l.price - fee);</code>

Royalties (ERC-2981)

The ERC-2981 standard lets creators earn a royalty on secondary sales. A marketplace queries royaltyInfo and pays the creator their share.

<code>function royaltyInfo(uint256 tokenId, uint256 salePrice)
    external view returns (address receiver, uint256 royaltyAmount);</code>

Cancelling a Listing

Sellers should be able to remove their listing. Only the original seller may cancel.

<code>function cancel(bytes32 id) public {
    require(listings[id].seller == msg.sender, 'not seller');
    delete listings[id];
}</code>

Off-Chain Order Books

Large marketplaces like OpenSea avoid storing every listing on-chain. Instead sellers sign orders off-chain, and the contract only runs the transfer when a buyer submits a matching signed order. This saves enormous gas.

Security Considerations

Marketplaces are high-value targets. Guard against reentrancy, validate ownership and approvals at execution time, and never trust prices or addresses from untrusted input without checks.

Quick Check

Test your understanding of NFT marketplaces.

Recap

You learned how NFT marketplaces operate:

  • Sellers approve the marketplace, which then transfers on sale (no escrow needed)
  • Listings store seller, NFT, tokenId, and price
  • Buying transfers the NFT and forwards payment, deleting the listing first (checks-effects-interactions)
  • Fees and ERC-2981 royalties split the proceeds
  • Big marketplaces use off-chain signed orders to save gas
無料で開始

AI チューターと学ぶ Web3 & DApp Development Fundamentals — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
29
レッスン
105

よくある質問

「マーケットプレイス」レッスンは無料ですか?

はい。「マーケットプレイス」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Web3 & DApp Development Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Web3 & DApp Development Fundamentalsコースには全4レッスンが含まれています。

「マーケットプレイス」で何を学びますか?

出品と転送 ブラウザで直接実行するハンズオンコードでWeb3 & DApp Development Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Web3 & DApp Development Fundamentalsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのWeb3 & DApp Development Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「マーケットプレイス」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このWeb3 & DApp Development Fundamentalsレッスンでコードを書いて実行できますか?

はい。すべてのWeb3 & DApp Development Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ERC-721標準
  2. NFTのミント
  3. トークンメタデータ
  4. マーケットプレイス
← Web3 & DApp Development Fundamentalsに戻る