I am trying to understand how to use the ERC721 token.I want to change the function mint with parameter of type uint256 to parameter of type string and create a unique string, it's possible to replace uint256 tokenid to string ?.


UniqueString("test"); //good

And the next time will call the function with the same string("test") we will got error .

function UniqueString(string tokenid) public{


My question is how to create a unique string with the erc721 token. Thanks you in advance


As per the documentation for the ERC721 standard, if you want your token to be ERC721 compliant, then the tokenId must be a uint256.

Every NFT is identified by a unique uint256 ID inside the ERC-721 smart contract. This identifying number SHALL NOT change for the life of the contract. The pair (contract address, uint256 tokenId) will then be a globally unique and fully-qualified identifier for a specific asset on an Ethereum chain. While some ERC-721 smart contracts may find it convenient to start with ID 0 and simply increment by one for each new NFT, callers SHALL NOT assume that ID numbers have any specific pattern to them, and MUST treat the ID as a "black box".

However, if you want a tokenId based on a string, you could make the tokenId the hash of the string identifier. As noted in the ERC721 documentation:

The choice of uint256 allows a wide variety of applications because UUIDs and sha3 hashes are directly convertible to uint256.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.