StarknetByExample icon indicating copy to clipboard operation
StarknetByExample copied to clipboard

Feature: ERC721 NFT Contract

Open julio4 opened this issue 1 year ago • 12 comments

Description

In this feature, we will implement a simple ERC721 Non-Fungible Token (NFT) contract. This will allow the creation, transfer, and management of NFTs. Users will be able to mint new NFTs, transfer ownership, and query the ownership and metadata of their NFTs.

Criteria:

  • Keep it simple, focus on explaining the interface methods with a minimal implementation
  • Include comprehensive tests
  • Deploy the contract on a testnet

Resources:

ODHack

To be eligible for additional rewards, be sure to review and follow the ODHack Common Guidelines and Contributing Guidelines. Be sure to join the telegram group and introduce yourself.

julio4 avatar May 28 '24 08:05 julio4

Hello @julio4 I'll like to be assigned to this

raizo07 avatar May 28 '24 08:05 raizo07

i can do this

the-first-elder avatar May 28 '24 10:05 the-first-elder

@julio4 I'd like to take on the task of implementing and testing the ERC721 NFT contract. Here's my plan

What I'll Implement:

ERC721 Contract: Mint new NFTs. Transfer NFT ownership. Query ownership and metadata.

Interface Methods: Minting: Create new NFTs. Transferring: Transfer ownership of NFTs. Querying: Get ownership and metadata of NFTs.

Plan: Implementation:

I will follow the ERC721 standard. I will use minimal implementation for clarity. I will refer to OZ ERC721 and our ERC20 for guidance.

Comprehensive Tests:

Test minting functionality. Test transferring functionality. Test querying ownership and metadata. Cover edge cases like invalid transfers and minting. I will also deploy the contract on a testnet to verify functionality.

Example Test Cases: Minting:

Ensure new NFTs are created correctly. Verify metadata is set correctly.

Transferring:

Ensure ownership is transferred correctly. Handle invalid transfers.

Querying:

Verify correct ownership details. Check metadata retrieval.

I think this should cover everything needed to make sure the NFT721 contract works correctly. Let me know if I can take this on. Thank you

Timilehin-bello avatar May 28 '24 11:05 Timilehin-bello

Hello @julio4 I would like to be assigned to this. I am currently working on an ERC721 contract and I'm about to write tests for it. I can rewrite it to follow the pattern used for the ERC20 contract. I added an image to show what I am currently working on. image Thank you

BenFaruna avatar May 28 '24 20:05 BenFaruna

Hi, @julio4,

I would like to help with this one if it hasn't been assigned yet. I have extensive experience with Solidity and smart contract development. Here’s my plan:

  • Implement the ERC721 NFT contract focusing on minting, transferring, and querying ownership and metadata, leveraging OpenZeppelin's ERC721 for security and compliance.
  • Write comprehensive tests to cover all interface methods, ensuring correctness and robustness.
  • Deploy the contract on a testnet to validate functionality in a live environment and provide deployment instructions.
  • I am confident I can complete this task within 4 days.

Thanks!

coxmars avatar May 28 '24 20:05 coxmars

Hello @julio4 I'll like to be assigned to this

@raizo07 assigned for now

julio4 avatar May 30 '24 02:05 julio4

@raizo07 Any updates on this?

julio4 avatar Jun 04 '24 14:06 julio4

Yes I'll be sending a PR today.

On Tue, 4 Jun 2024, 15:17 Jules Doumeche, @.***> wrote:

@raizo07 https://github.com/raizo07 Any updates on this?

— Reply to this email directly, view it on GitHub https://github.com/NethermindEth/StarknetByExample/issues/197#issuecomment-2147656190, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATKSYSQL7ILLYRMPN7L6W2LZFXD6JAVCNFSM6AAAAABIMPCYRWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBXGY2TMMJZGA . You are receiving this because you were mentioned.Message ID: @.***>

raizo07 avatar Jun 04 '24 14:06 raizo07

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have a background in smart contract development and blockchain technology, with a focus on Solidity programming. I’ve successfully implemented ERC20 tokens and understand the nuances of interacting with blockchain networks.

How I plan on tackling this issue

I would approach this issue with following steps

Design Contract: Implement a basic ERC721 contract using OpenZeppelin's library to handle NFT creation, transfer, and metadata management.

Interface Method, Focus on core ERC721 methods:

mint(address to, uint256 tokenId): Create new NFTs. transferFrom(address from, address to, uint256 tokenId): Transfer NFTs between addresses. ownerOf(uint256 tokenId): Query NFT ownership. tokenURI(uint256 tokenId): Retrieve metadata. Write Tests: Develop comprehensive tests to cover minting, transferring, and querying functionality using a framework like Hardhat or Truffle.

Deploy on Testnet: Deploy the contract on a testnet such as Rinkeby or Goerli, ensuring proper configuration and deployment.

ScottyDavies avatar Aug 26 '24 13:08 ScottyDavies

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have an extensive background in smart contract development, particularly with Ethereum and its token standards, including ERC20 and ERC721. My experience includes designing, implementing, and deploying smart contracts in Solidity using Hardhat and Foundry. For my involvement in various Web3 projects, I have developed a deep understanding of blockchain technology and its applications. This includes hands-on work with decentralized applications (dApps) and a strong command of JavaScript for front-end integration.

I have proficiency both in the theoretical and practical aspects of blockchain development. I have worked extensively with testnets to ensure that smart contracts are not only functional but also secure and optimized. This practical experience, coupled with my ability to write and execute comprehensive test cases, will enable me to tackle the implementation of the ERC721 NFT contract effectively. I am committed to following industry best practices and guidelines, ensuring a high-quality output that aligns with the project’s objectives.

How I plan on tackling this issue

I aim to deliver a well-executed ERC721 NFT contract that is not only functional but also well-documented and aligned with best practices. To address the task of implementing a simple ERC721 NFT contract, my approach would be:

  1. Conduct Initial Research and Analysis: My first step would involve a detailed review of the ERC721 standard, focusing on its core functionalities (minting, transferring, and querying NFTs). I will examine existing implementations and guidelines provided by OpenZeppelin to ensure compliance and best practices.

  2. Contract Development: I will utilize OpenZeppelin’s ERC721 implementation as a foundation, adapting it to meet the specific requirements of the feature while keeping the implementation straightforward.

  3. Testing and Validation: I will write thorough test cases to cover all aspects of the contract, including edge cases and error handling. This will involve testing scenarios such as token minting, transfers, and ownership queries to ensure the contract operates as expected.

  4. Deployment: Upon successful testing, I will deploy the contract to an Ethereum testnet Sepolia. This deployment will be documented with transaction details and the contract address for verification and further review.

  5. Documentation and Compliance: I will prepare detailed documentation that outlines the contract’s functionality and provides explanations for each method. Additionally, I will ensure that the implementation adheres to the ODHack Common Guidelines and Contributing Guidelines, and actively engage with the relevant community channels as advised.

livinalt avatar Sep 07 '24 20:09 livinalt

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a blockchain developer with experience in typescript, html, css, react, javascript cario and solidility . this would be my first time contributing to this ecosystem .. please i will love to be assigned to this issue

How I plan on tackling this issue

  1. Implement Basic ERC721 Contract: Start by importing OpenZeppelin's ERC721 implementation as a base. Define the NFT's name, symbol, and any specific token properties. Implement core functions for minting, transferring, and querying ownership.
  2. Interface Methods: Clearly explain each interface method and keep the implementation minimal while ensuring functionality is clear and concise.
  3. Comprehensive Testing: Write unit tests covering minting, transfers, and ownership queries. Ensure edge cases like invalid transfers and approvals are handled.
  4. Deployment on Testnet: After testing locally, deploy the contract to a testnet like Rinkeby or Goerli using Hardhat or Truffle. Verify deployment and functionality.
  5. Use Existing ERC20 as Reference: Leverage your previous ERC20 implementation for contract structure, especially with testing and deployment scripts.

ShantelPeters avatar Sep 28 '24 00:09 ShantelPeters

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have writen some starknet smart contract using cairo in which nft contract is part of it, I will be glad to contribute to the ecosystem.

How I plan on tackling this issue

My Approach:

I will follow the NFT contract standard and utilize the OpenZeppelin library for implementation. The functions will be defined in a clear interface and implemented in a simple, concise manner. To enhance functionality, I will include relevant events and custom errors. Each function will be thoroughly unit tested. Finally, I will deploy the contract on Starknet Sepolia and interact with it to ensure all functionalities work as expected.

Lukman-01 avatar Oct 04 '24 16:10 Lukman-01

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a Junior web developer, working with Javascript, HTML and CSS. I have over a decade experience designing graphics and organization branding.

How I plan on tackling this issue

I will follow the guidelines and put my creativeness to work

ajalaoluwasogo avatar Oct 12 '24 07:10 ajalaoluwasogo

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a Web3 front-end developer skilled in technical documentation and software development. I greatly understand technologies like JavaScript, Typescript, Cairo, Rust and Solidity. I have contributed successfully to open-source projects like Stark Quest and Speedrun scaffold-stark.

How I plan on tackling this issue

My Approach includes :

  • Thorough studying of the way ERC20 was implemented
  • Follow the same procedure in the implementation of the ERC721.
  • Create a Pull Request (PR).
  • Request for a Review.
  • Make changes based on the Review of the PR.

pheobeayo avatar Oct 17 '24 15:10 pheobeayo

Mind if I try this one?

jaiminRaiyani avatar Nov 04 '24 04:11 jaiminRaiyani

Mind if I try this one?

It'll be closed by #250

julio4 avatar Nov 04 '24 08:11 julio4

To implement a simple ERC721 Non-Fungible Token (NFT) contract, we will follow the ERC721 standard using OpenZeppelin's contracts. Below is a minimal implementation of the ERC721 contract, along with explanations of the interface methods, comprehensive tests, and deployment instructions on a testnet.

// SPDX-License-Identifier: MIT pragma solidity ^0.8.9;

// Import OpenZeppelin contracts import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; import "@openzeppelin/contracts/access/Ownable.sol";

contract MyNFT is ERC721, ERC721URIStorage, Ownable { uint256 public tokenCounter;

constructor() ERC721("MyNFT", "MNFT") {
    tokenCounter = 0; // Initialize the token counter
}

/// @dev Mint a new NFT with a unique token ID and metadata URI
function mintNFT(string memory tokenURI) public onlyOwner {
    uint256 newTokenId = tokenCounter;
    _safeMint(msg.sender, newTokenId); // Mint the NFT to the sender
    _setTokenURI(newTokenId, tokenURI); // Set the metadata URI for the NFT
    tokenCounter++; // Increment the counter for the next token
}

/// @dev Override the base URI function to return a custom base URI if needed
function _baseURI() internal view virtual override returns (string memory) {
    return "https://api.mynft.com/metadata/"; // Example base URI
}

} You can use Hardhat or Truffle for testing your smart contract. Below is an example of how you might set up tests using Hardhat:

const { expect } = require("chai"); const { ethers } = require("hardhat");

describe("MyNFT Contract", function () { let myNFT; let owner; let addr1;

beforeEach(async function () {
    const MyNFT = await ethers.getContractFactory("MyNFT");
    myNFT = await MyNFT.deploy();
    [owner, addr1] = await ethers.getSigners();
});

describe("Minting NFTs", function () {
    it("Should mint a new NFT and set its metadata URI", async function () {
        await myNFT.mintNFT("https://example.com/metadata/1");
        const ownerOfToken = await myNFT.ownerOf(0);
        const tokenURI = await myNFT.tokenURI(0);
        expect(ownerOfToken).to.equal(owner.address);
        expect(tokenURI).to.equal("https://example.com/metadata/1");
    });

    it("Should fail if a non-owner tries to mint", async function () {
        await expect(myNFT.connect(addr1).mintNFT("https://example.com/metadata/2"))
            .to.be.revertedWith("Ownable: caller is not the owner");
    });
});

}); Create a deploy script in scripts/deploy.js: async function main() { const MyNFT = await ethers.getContractFactory("MyNFT"); const myNFT = await MyNFT.deploy(); await myNFT.deployed(); console.log("MyNFT deployed to:", myNFT.address); }

main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); });

GradleD avatar Nov 05 '24 08:11 GradleD

Could I take a shot at this?

Amarjeet325 avatar Nov 21 '24 05:11 Amarjeet325

Hi, I am proficient Blockchain developer expert in Cairo , Rust and Solidity . I have contributed many stark net project and more . please /assign this issue . Thank You

ryzen-xp avatar Nov 21 '24 06:11 ryzen-xp

Let me try this one!

MrRoudyk avatar Nov 21 '24 09:11 MrRoudyk

This issue was already done by @0xNeshi and will be merged after review.

julio4 avatar Nov 21 '24 09:11 julio4

i can do this

Nanle100 avatar Nov 30 '24 23:11 Nanle100