Giter Site home page Giter Site logo

erc721r / erc721r Goto Github PK

View Code? Open in Web Editor NEW
97.0 97.0 27.0 494 KB

An ERC721 base contract that mints tokens in a pseudo-random order. Because the token is revealed in the same transaction as the mint itself, this contract creates a fun but not fully secure experience.

License: MIT License

Solidity 44.90% JavaScript 55.10%

erc721r's People

Contributors

roger-wu avatar rogerpodacter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

erc721r's Issues

_mintRandom ERC721REnumerable

Hey! I love this 721 feature and its accompanied documentation! Thank you for all the work done in brining this to the Ethereum developer community.

I am wanting to use the ERC721REnumerable in an upcoming project but having issues in using the tokenOfOwnerByIndex. Specifically, only the 0-index owner's token is showing a randomly generated index value.

I'm checking to see if I am implementing the Enumerable contract correctly. Here is the basic contract structure Im using for tests:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./ERC721REnumerable.sol";

contract TEST is ERC721rEnumerable {    

    constructor(string memory name_, string memory symbol_, uint maxSupply_) ERC721r(name_, symbol_, maxSupply_) {}

    function mint(uint256 quantity) public {
        _mintRandom(msg.sender, quantity);
    }

}

And here is my mocha.js test:

const assert = require('assert');
const ganache = require('ganache-cli');
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider(HDWalletProvider));
const { abi, bytecode } = require('../../build/contracts/TEST.json')

let accounts;
let contract;

beforeEach( async () => {

    accounts = await web3.eth.getAccounts();
    contract = await new web3.eth.Contract(abi).deploy({data:bytecode, arguments: ['TEST', 'TEST', 777]}).send({from:accounts[0], gas:5000000})

})

describe( 'Mint Tests', () => {    
    
    it.skip("Contract Deploys", () => {
        assert(contract)
    })

    // this test passes
    it('Mint 1 Token', async () => {
        await contract.methods.mint(1).send({from: accounts[0], gas:1000000})
        const tokens = await contract.methods.balanceOf(accounts[0]).call()
        assert(tokens,1)
    })


    // this test passes
    it.skip('Mint 1 Token & Call Random TokenIdx', async () => {
        await contract.methods.mint(1).send({from: accounts[0], gas:1000000})
        const tokenIdx = await contract.methods.tokenOfOwnerByIndex(accounts[0],0).call()
        console.log(`Randomly Assigned Token Index: ${tokenIdx}`)
        assert.notEqual(0,tokenIdx)
    })

    // this test FAILS (see below)
    it('Mint Multiple Tokens & Call Random TokenIdx of all Tokens', async (numMints=10) => {                

        await contract.methods.mint(numMints).send({from: accounts[0], gas:1000000})
        const tokens = await contract.methods.balanceOf(accounts[0]).call()
        assert.equal(tokens, numMints)

        for (let i=0; i< numMints; i++ ){
            let tokenIdx = await contract.methods.tokenOfOwnerByIndex(accounts[0],i).call()
            console.log(`Randomly Assigned Token Index: ${tokenIdx}`)
            assert.notEqual(0,tokenIdx)
        }        
         
    })

})

The output for the last test is as follows:

  Mint Tests
    - Contract Deploys
    ✔ Mint 1 Token (108ms)
Randomly Assigned Token Index: 513
    ✔ Mint 1 Token & Call Random TokenIdx (82ms)
Randomly Assigned Token Index: 442
Randomly Assigned Token Index: 0
    1) Mint Multiple Tokens & Call Random TokenIdx of all Tokens


  2 passing (779ms)
  1 pending
  1 failing

  1) Mint Tests
       Mint Multiple Tokens & Call Random TokenIdx of all Tokens:
     AssertionError [ERR_ASSERTION]: 0 != '0'
      at Context.<anonymous> (test/mint.test.js:46:20)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

Any suggestions/feedback would be greatly appreciated!

Flashbots Exploit

Believe Flashbots are still able to exploit since they interact as EOA.

Starting NFT ID

Could you include some docs on the lowest NFT ID that this contract generates?

Is the first NFT 0 or 1? There is mention of ERC721A where the ID is 0, and most other contracts use 1, it would be great to document this.

Great!

Hi,

Is it possible to integrate this without needing to include this erc721R file; could you make an example which just indicates that to add to a typical erc721 contract?

I want to use your approach, although I might tailor it to use a VRF2 random number for the shuffle as that would improve fairness.

I also notice you added a means for the owner to claim a specific id from the collection; this is perfect, as there are a few NFT I wish to handpick as prizes.

This is a godsend to me, I just need a little assistance implementing it; feel free to message @coeus_crypto on Telegram!

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.