πŸ›’Marketplace

Name
Description

OnChainMarketplace

Implementation of an on-chain marketplace supporting orders and offers for both ERC-721 and ERC-1155 token standards.

HybridMarketplace

Currently under development. Adds off-chain signature-based NFT selling capability to the OnChainMarketplace contract.

OnChainMarketplace

This guide provides an in-depth look at how to interact with the OnChainMarketplace smart contract using Solidity. It focuses on the key functions required for creating orders, making offers, accepting offers, and fulfilling orders within the marketplace.

Overview

The OnChainMarketplace smart contract supports both ERC-721 and ERC-1155 tokens and provides mechanisms for order creation, offer management, and transaction execution, directly through blockchain interactions.

Order Creation

Orders in this marketplace are created automatically when NFTs are transferred to the contract. This happens through the ERC-721 wallet interface and ERC-1155 wallet interface as defined in the EIPs:

  • ERC-721 (onERC721Received): Triggered when an ERC-721 token is transferred to the contract.

  • ERC-1155 (onERC1155Received): Triggered when an ERC-1155 token is transferred.

  • ERC-1155 ( onERC1155BatchReceived ): Triggered when multiple ERC-1155 tokens are transferred via batch transfers.

Both functions decode the incoming data and create or modify orders based on the token type and details provided.

Making Offers

To make an offer on an NFT, interact with the createOffer function:

function createOffer(
    uint256 tokenId,
    uint256 unitPrice,
    uint256 ERC1155Value,
    address collection,
    address from
) external payable
  • tokenId: The ID of the token for which the offer is being made.

  • unitPrice: The price for each unit of the token.

  • ERC1155Value: The amount of ERC1155 tokens being offered for (set to 0 for ERC-721).

  • collection: The address of the NFT contract.

  • from: The address of the buyer making the offer.

The value sent with the transaction (msg.value) should match the total amount of the offer, calculated as unitPrice * ERC1155Value.

Accepting Offers

Sellers can accept offers using the acceptOffer function:

  • orderId: ID of the existing order.

  • offerId: ID of the offer being accepted.

  • ERC1155Value: Number of tokens being sold (useful for partial fills in ERC1155).

  • commissionBps: Commission basis points for the sale.

  • commissionReceivers: Addresses that will receive the commission.

Fulfilling Orders

To purchase an NFT directly at the listed price, use the fillOrder function:

  • orderId: The ID of the order being fulfilled.

  • buyer: The address of the buyer, which can be used to specify a different recipient of the NFT.

  • ERC1155Value: Specifies the number of ERC1155 tokens being purchased (set to 0 for ERC-721 tokens).

The msg.value must be equal to the total purchase amount, which is the order’s unitPrice multiplied by ERC1155Value (or just unitPrice for ERC-721).

Additional Functionalities

  • Updating and Canceling Offers: Offers can be modified or withdrawn using functions designed for adjusting the terms or removing the offer entirely.

  • Admin Functions: Functions like setFeeRecipient and setMarketFee allow the marketplace owner to adjust operational parameters such as fee collection addresses and rates.

Conclusion

When using the OnChainMarketplace, it is essential to understand the flow of creating, modifying, accepting, and fulfilling orders and offers. Each function is designed to ensure secure and efficient transactions compliant with ERC-721 and ERC-1155 standards. This guide should serve as a foundational tool for developers looking to utilize this contract in deploying a fully functional on-chain NFT marketplace.

Last updated