contracts-wizard icon indicating copy to clipboard operation
contracts-wizard copied to clipboard

ERC721 safeMint should return the tokenId

Open nkavian opened this issue 3 years ago • 4 comments

When auto increment ids are enabled, shouldn't the method also then return tokenId? Otherwise how would you know what token was minted?

image

nkavian avatar Jan 05 '23 23:01 nkavian

Otherwise how would you know what token was minted?

Do you mean when you invoke this function off-chain? In that case you would use the Transfer event, and in fact the return value wouldn't be available.

Or do you have another scenario in mind?

frangio avatar Jan 09 '23 21:01 frangio

The contract caller doesn't know the value of the new tokenId that was generated. I'm suggesting an implementation like this:

function safeMint(address to) public onlyOwner returns (uint256) {
    uint256 tokenId = _tokenIdCounter.current();
    _tokenIdCounter.increment();
    _safeMint(to, tokenId);
    return tokenId;
}

nkavian avatar Jan 09 '23 21:01 nkavian

can i work on this issue @ericglau

EthixLucifer avatar Apr 06 '24 03:04 EthixLucifer

@EthixLucifer Sure, thanks. You can find development setup steps in the readme.

ericglau avatar Apr 10 '24 16:04 ericglau