Coder Social home page Coder Social logo

erc-721-smart-contract-'s Introduction

NFT SMART CONTRACT

  1. Imports: This contract imports two other contracts from OpenZeppelin's library, ERC721 for ERC721 standard functionality (NFT creation, ownership, etc.) and Ownable for ownership related functionality (onlyOwner modifier).

  2. Rabbits Contract: This contract is a subclass of ERC721 and Ownable contracts with additional features. The contract mints ERC721 tokens (Rabbits) and tracks their ownership.

  3. State Variables:

    • _nextTokenId is a private variable used to track the next tokenId to be minted. It's initialized to 0.
    • baseURI is a private string variable used to store base URI for token URIs.
    • walletMints is a mapping from an address to a uint256 tracking how many tokens have been minted by each address.
    • URIQueryForNonExistentToken is a custom error thrown when trying to get a token URI for a non-existent token.
  4. Constructor: The constructor initializes baseURI with a string argument uri and sets initialOwner as owner of this contract.

  5. Functions:

    • _baseURI returns the current baseURI string.
    • setBaseURI allows owner to set a new baseURI string.
    • safeMint mints a new token to sender's address (only owner can call this). It increments _nextTokenId and walletMints[msg.sender] by 1.
    • contractURI returns a fixed string (IPFS link) for OpenSea metadata.
    • tokenURI returns a token URI string for a given tokenId. If tokenId is not valid (greater than or equal to _nextTokenId), it reverts with custom error URIQueryForNonExistentToken. The URI is composed of baseURI, tokenId (as a string), and ".json".
    • getBalance returns how many tokens an address owns. This is a simple balance checker for this contract. It returns balance of given address.
  6. Function contractURI():

    • Opensea expects this function to create NFT collection for contracts ERC721 and ERC1155, it must contain a JSON file similar to :

{ "name": "OpenSea Creatures", "description": "OpenSea Creatures are adorable beings primarily for demonstrating what can be done using the OpenSea platform. Adopt one today to try out all the OpenSea buying, selling, and bidding feature set.", "image": "https://violet-tiny-ocelot-777.mypinata.cloud/ipfs/QmcfxpxZFB4szGooppDTsscefKwoq8eDwkSic8JgwHKh5w/1.jpg", "banner_image": "https://violet-tiny-ocelot-777.mypinata.cloud/ipfs/QmcfxpxZFB4szGooppDTsscefKwoq8eDwkSic8JgwHKh5w/1.jpg", "external_link": "https://github.com/iamcarllosjr", "collaborators": ["0xA5216C6F685c2b8a678A704107760Be652665234"] }

This contract can be deployed on Ethereum blockchain to create a collection of NFTs (Rabbits). Owner of this contract can mint new tokens, set base URI for tokens, check how many tokens an address owns etc. It's a simple example of how to create an NFT collection with ERC721 standard using OpenZeppelin's contracts in Solidity.

erc-721-smart-contract-'s People

Contributors

iamcarllosjr avatar

Watchers

 avatar

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.