GithubHelp home page GithubHelp logo

printfjoby / nftmarketplace Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 871 KB

This is a Solidity smart contract for an NFT marketplace that facilitates the trading of ERC721 tokens.

Solidity 56.09% JavaScript 43.91%

nftmarketplace's Introduction

NFT Marketplace

This is a Solidity smart contract for an NFT marketplace that facilitates the trading of ERC721 tokens. It extends the functionality of the ERC721URIStorage contract from the OpenZeppelin library.

Contract Details

Structs

  • Token: Represents an ERC721 token with the following properties:
    • tokenId: The unique identifier of the token.
    • seller: The address of the token seller.
    • owner: The address of the current token owner.
    • price: The price of the token.
    • sold: Indicates whether the token has been sold.

Storage Variables

  • _tokenIds: The total number of tokens created.
  • _itemsSold: The total number of tokens sold.
  • _listingPrice: The listing price for creating tokens.
  • _owner: The address of the marketplace owner.
  • idToToken: A mapping from token IDs to their corresponding Token struct.

Events

  • TokenCreated: Emitted when a new token is created.
  • TokenSold: Emitted when a token is sold.
  • ResaleCreated: Emitted when a token is resold.

Functions

Constructor

  • constructor(): Initializes the NFT marketplace contract. It sets the listing price and the contract owner.

Modifiers

  • onlyOwner(): Throws an error if the caller is not the marketplace owner.

External Functions

  • updateListingPrice(uint256 listingPrice): Updates the listing price for creating tokens.
  • getListingPrice(): Retrieves the current listing price.
  • createToken(string memory tokenURI_, uint256 price): Creates a new token with the specified token URI and price.
  • buyToken(uint256 tokenId): Buys a token with the specified token ID.
  • resellToken(uint256 tokenId, uint256 price): Resells a token with the specified token ID and price.
  • fetchAllUnsoldTokens(): Fetches all unsold tokens.
  • fetchTokensOwnedByMe(): Fetches tokens owned by the caller.
  • fetchMyListedTokens(): Fetches tokens listed by the caller.

The contract allows users to create, buy, and resell ERC721 tokens. It also provides functions to fetch unsold tokens, tokens owned by the caller, and tokens listed by the caller.

Note: This contract inherits the ERC721URIStorage contract, which provides additional functions for setting and retrieving the token URI for each token.

To use this contract, you need to import the necessary dependencies from the OpenZeppelin library:

  • ERC721.sol: Provides the implementation of the ERC721 token standard.
  • ERC721URIStorage.sol: Extends the ERC721 contract and adds support for setting and retrieving token URIs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.