GithubHelp home page GithubHelp logo

nibbstack / erc721 Goto Github PK

View Code? Open in Web Editor NEW
1.0K 33.0 390.0 2.45 MB

The reference implementation of the ERC-721 non-fungible token standard.

License: MIT License

JavaScript 32.25% Solidity 67.75%
ethereum contract contracts eth erc721 token tokens standard implementation smart-contracts

erc721's People

Contributors

chiefpulpo avatar dafky2000 avatar flockonus avatar fulldecent avatar lknix avatar mg6maciej avatar momannn avatar nikhildesai27 avatar tchajed avatar xpepermint 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  avatar  avatar  avatar

Watchers

 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

erc721's Issues

Remove truffle compilation warnings

After updating to the latest version of solidity we can see the warnings below:

Compilation warnings encountered:

/Users/xpeper/Work/0xcert.org/repositories/ethereum-erc721/contracts/tokens/ERC721.sol:142:3: Warning: Functions in interfaces should be declared external.
  function getApproved(
  ^ (Relevant source part starts here and spans across multiple lines).
,/Users/xpeper/Work/0xcert.org/repositories/ethereum-erc721/contracts/mocks/NFTokenMetadataEnumerableMock.sol:6:1: Warning: Base constructor arguments given twice.
contract NFTokenMetadataEnumerableMock is NFTokenEnumerable, NFTokenMetadata {
^ (Relevant source part starts here and spans across multiple lines).
/Users/xpeper/Work/0xcert.org/repositories/ethereum-erc721/contracts/tokens/NFTokenEnumerable.sol:35:5: First constructor call is here:
    NFToken()
    ^-------^
/Users/xpeper/Work/0xcert.org/repositories/ethereum-erc721/contracts/tokens/NFTokenMetadata.sol:35:5: Second constructor call is here:
    NFToken()
    ^-------^

5300 Gas Cost for Unnecessary State Change

In the removeNFToken function in the NFTokenEnumerable.sol file ownerToIds[_from][lastTokenIndex] is set to 0 twice instead of once. This is redundant and costs about 5300 extra gas.

Here is the code I am talking about:

 ownerToIds[_from][lastTokenIndex] = 0;
 
 ownerToIds[_from].length--;

The first line obviously sets ownerToIds[_from][lastTokenIndex] to 0. Reducing the length of the array also sets ownerToIds[_from][lastTokenIndex] to 0.

So it makes sense to get rid of this line: ownerToIds[_from][lastTokenIndex] = 0;.

ERC 721: canTransfer should modify _transfer function

I think canTransfer modifier should be moved to private _transfer function instead of other wrapping functions. If somebody decides to build upon our implementation then decoupling these could pose a serious risk: one just needs to add another function which calls _transfer and forget to add the modifier. Or changes _transfer to external.

ERC 721: Code reuse

If issue #9 gets accepted then _safeTransferFrom should just call transferFrom before checking if recipient is a contract.

Bug bounty program for ERC-721 smart contracts (v1)

The 0xcert team has decided to provide a valid and secure ERC-721 implementation for the Ethereum community. We recognize the need and necessity of a security audit in order to keep all further usage safe and secure. In this light, a bug bounty program is being launched and we would love if the community can help find and disclose security issues and vulnerabilities.

About implementation

ERC-721 is a standard interface for non-fungible tokens on the Ethereum blockchain, invented by Dieter Shirley and written by William Entriken. The 0xcert development team decided to build the fully compatible implementation, which is going to be open-source and available to everyone.

Scope & rules

This bug bounty program will run from 2018-05-16 at 00:01 CET to 2018-07-16 at 23:59 CET. All of the discussions and code in this bug bounty program are publicly available in this repository. Help us find any problems with the ERC-721 implementation and you will be rewarded.

  • Be descriptive and detailed when describing your issue.
  • Fix it and recommend a way to solve the problem.
  • Include a truffle or detailed test case that we can reproduce.
  • Issues that have already been published here or are already disclosed to the 0xcert team are not eligible for rewards.
  • Social engineering, XKCD#538 attacks, bringing down Ropsten/Metamask/Infura are not in scope and will NOT be paid a reward.
  • Only the contracts regarding the ERC-721 are in scope, our website is not in scope.
  • GitHub issues is the only way to report issues and request rewards.
  • The 0xcert team has a complete and final judgment on the acceptability of issue reports.

Rewards

  • We will distribute up to 5 ETH among all participants that reported a unique high severity bug.
  • Reports for medium and low bugs will receive our 0xcert t-shirt and an honorable mention.
Severity Examples
High Allowing tokens to get lost, stolen, or become unusable.
Medium An undocumented function, documentation of a user-facing function that does not completely explain what is happening from the user’s perspective (i.e. unspecified side effects).
Low Any typo that does not affect program functionality. Recommended changes to functionality which are helpful and optimize the code.

Note that if the EIP standard is amended then an issue will be Low severity if it points this out to us. We will support the updated standard.

Additional bounty

We are providing another bounty for a token that builds on top of this implementation called Xcert. If you are interested in participating in that bounty you can check it out here: 0xcert/ethereum-xcert#24

How will i fetch .json files from build folder in truffle using truffle console?

Hi,
How will I call .json files from build folder Truffle...?Truffle migration successfully completed..I worked in Privatenet...Then I tried


truffle console
truffle(development)> const { abi } = require('./build/contracts/MyNFT.json');
**Undefined**

Please help me to figured out this issue? Why it's showing undefined?

[bug] Resetting of value to non-zero when burning last token

When burn is called on the last token, code in removeNFToken will not clear idToOwnerIndex for it.
Order of these statements should be changed, but even better to use check for last token mentioned in previous issue #104.

    idToOwnerIndex[_tokenId] = 0;
    idToOwnerIndex[lastToken] = tokenToRemoveIndex;

`clearApproval` should not fire event

Because this function is called only from _burn and _transfer in which cases also Transfer is emitted, clearApproval should only set state to 0 (might be more gas efficient to do it conditionally).

According to spec (https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md)

    ///  When a Transfer event emits, this also indicates that the approved
    ///  address for that NFT (if any) is reset to none.
    event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);

OZ also does it incorrectly, but "slightly" better.
https://github.com/OpenZeppelin/openzeppelin-solidity/blob/07020e954475a4fdd36e0252e88717b60f790b71/contracts/token/ERC721/ERC721BasicToken.sol#L300-L303

Add LICENSE file

README.md includes the line Licence (MIT).

Can you please add the appropriate LICENSE file to the repo.

Deploy main net

Just for fun, could you please:

Then you can add to the README:

We deployed a contract you can play with RIGHT NOW. No need to install software. In this test version of the contract, anybody can mint or burn tokens, so don't use it for anything important.

Mainnet address: xxxxx
Ropsten address: xxxxx

Add selling points

Every GitHub project needs selling points

  • Complete implementation (all functions implemented)
  • XX% code coverage Truffle testing
  • It is subclassable so you can add your own features while relying on our base work
  • The code is verified by the community and has an active bug bounty

PrivateNet Integration

Hi,
Is this code only worked in Ropsten? I just want to integrate this code to my private Net.
I saw one command : npm run migrate -- --network Ropsten ( works in Ropsten) instead of this I used
npm run migrate -- --network localhost:8545. But it's not connecting. How will I resolved my issue?
My network id : 54 ( That i gave to truffle.js).

Consider providing enumerable + metadata token

I believe name of NFToken could be misleading as users might think this is the one they would want to use. I suggest renaming it to NFTokenBasic and adding new one NFToken (or NFTokenFull) that only extends NFTokenEnumarable and NFTokenMetadata.

[optimization] Gas use in `removeNFToken`

These two lines don't need to be executed when tokenToRemoveIndex == lastTokenIndex.

    ownerToIds[_from][tokenToRemoveIndex] = lastToken;
    ownerToIds[_from][lastTokenIndex] = 0;

Next line covers clearing it:

    ownerToIds[_from].length--;

Metadata extension is not compliant

Currently metadata is not compliant with the standard. Standard is pure, implementation is view.

Will consider to change the standard because everyone is doing this. But for now this should be noted.

Comply with 165

The NFToken constructor should invoke the SupportsInterface constructor.

ERC721 Enumerable: purpose of idToIndex?

We set it in _mint function and don't use it anywhere.

contracts/tokens/ERC721EnumerableImplementation.sol:  mapping(uint256 => uint256) internal idToIndex;
contracts/tokens/ERC721EnumerableImplementation.sol:    idToIndex[_id] = tokens.length;

Update and refactor tests

Tests should be testing a single unit (function). Currently we don't test all functions directly since some of them are tested through other functions. This doesn't follow the best practices because it's misleading when tests start to fail and it leaves out edge cases. Ideally, tests should:

  1. Every test should test a single unit.
  2. Every test should set up the required contract state directly prior to testing.
  3. Every unit should be fully covered.

Token naming suggestions

How about if we change current naming that:

  1. ERC721.sol (interface) -> ERC721Interface.sol or ERC721Standard.sol and ERC721implementation.sol -> ERC721.sol;
  2. Alternatively we move interfaces in tokens/interfaces and name both ERC721.sol (interface and implementation).

If the plan is that our implementation gets reused then we need to have simpler names. ERC721implementation is way too long and verbose. Thoughts?

ERC 721: incomplete case for _mint

There is currently only internal _mint function, which can't be used. Either we complete it with some external function for minting or add a comment describing this is by default NOT implemented / used. We probably want to keep it since it has the code which shows how to properly mint a token using our implementation.

Error getting while executing transferFrom function calling

Hi,
When I am trying to execute
const { abi } = require('./build/contracts/MyNFToken.json');

const account0 = '0x294a4c67667565765668e3329a2b219a1f3d8c22'; // for eg: owner address
const account1 = '0x294a4c67670c0dae6ce8e3329a2b219a1f3d8c22'; // another account (you can create it)
const MyNFTokenContract = web3.eth.contract(abi);
const MyNFTokenInstance = MyNFTokenContract.at();
MyNFTokenInstance.transferFrom(account0,account1,"1234");
Error: invalid address
at SolidityFunction.execute (/usr/local/lib/node_modules/truffle/build/webpack://web3/lib/web3/function.js:256:1)
at SolidityFunction.sendTransaction (/usr/local/lib/node_modules/truffle/build/webpack:/
/web3/lib/web3/function.js:170:1)
at Eth.send [as sendTransaction] (/usr/local/lib/node_modules/truffle/build/webpack://web3/lib/web3/method.js:139:1)
at Method.toPayload (/usr/local/lib/node_modules/truffle/build/webpack:/
/web3/lib/web3/method.js:114:1)
at Method.formatInput (/usr/local/lib/node_modules/truffle/build/webpack://web3/lib/web3/method.js:88:1)
at Array.map ()
at /usr/local/lib/node_modules/truffle/build/webpack:/
/web3/lib/web3/method.js:89:1
at inputTransactionFormatter (/usr/local/lib/node_modules/truffle/build/webpack://web3/lib/web3/formatters.js:100:1)
at inputAddressFormatter (/usr/local/lib/node_modules/truffle/build/webpack:/
/web3/lib/web3/formatters.js:274:1)
Why its showing like that? (mint,balanceof,safeTransferfrom is working but for approval,setApproveForAll etc is not working...showing same error only);
I have done in PrivateNet.
Help me to resolve this issue...

Gas use optimization - removing `ownerToNFTokenCount`

If you move implementation of tokenOfOwnerByIndex and related fields (ownerToIds and idToOwnerIndex) to NFToken, you can remove ownerToNFTokenCount and use ownerToIds[_owner].length in balanceOf. This saves gas on two updates of ownerToNFTokenCount every time token is transferred and one when minted or burned.

This doesn't break compatibility with ERC721 spec, as you may leave ERC721 and ERC721Enumerable as they are now.
This has drawback of slightly more expensive deploy and transfers for simpler NFToken, but is cheaper for full NFTokenEnumerable (+ NFTokenMetadata) and assuming OpenSea and others will require enumeration and developers will want to be listed there, this makes it cheaper in most cases. Also additional, non-standard funcitonality provided by tokenOfOwnerByIndex in basic NFToken might be a good thing.

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.