Hello everyone, I am just faced with unique identifiers in solidity. In my app 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 25, 2023, 10:05 AM
just use increment of counter. In your case no need use cahinlink or other services.
Oct 28, 2023, 4:02 PM
yeah for a simple incremental (number based) ids nonce is good enough
Oct 28, 2023, 10:48 PM

© 2024 Draquery.com All rights reserved.