I am trying to understand how to use the ERC721 token. I want to change the function mint with a parameter of type uint256 to the 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 when I call the function with the same string("test") we get an error.

function UniqueString(string tokenid) public{

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

1 Answer 1


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.

  • 1
    So can those hashedID should be passed as a parameter?
    – Volatil3
    Aug 20, 2021 at 18:28
  • yeah you can keckack256 of your string and use output of hash which is bytes32 as string but token tracker won't be able to track your tokens as they use the method signature of uint256 token id. Feb 6, 2023 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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