Hello everyone, I am just faced with unique identifiers in solidity. In my project users should be able to register themselves and later user should be able to add a car post. So both user entity and car entity should have a unique Id.
And I am tried to research in the internet how to generate a unique id’s in solidity and as I understand there are 3 main options:

1) Just create a function that will increment an ID and return it’s value each time a new entity will be created.(But this method is too primitive)

2) Hash some data about entity(like email) with keccak256() + abi.encode function to make the result more protected. Or instead of entity info I saw a lot of examples that use a block.timestamp and block.difficulty. —> But as I understood, by using these methods, I will generate not a truly random ID, and it is not a safe way by multiple reasons.

3) I also read about VRF Chainlink random number generator, that this is the best way to generate a random number(like for casino, or lottery).

I understand that ID should be a unique, but I am not sure that to generate an ID I should use VRF from Chainlink.
The question: maybe someone can recommend me what is the best way to generate a random number for ID’s in Solidity?

Thanks!

Oct 27, 2023, 6:36 AM
have a nonce, increment it, hash that number with some unique detail of the product and done you should get a semi random number that's somewhat safe
Oct 28, 2023, 9:15 AM
Okay got it! Thanks!!
Oct 28, 2023, 9:54 AM

© 2024 Draquery.com All rights reserved.