Search code examples
soliditytruffle

input validation in solidity


I'm programming a Dapp. I need to calculate the area of a geographical coordinates (geo polygon). Can I calculate the area of these geographic coordinates on the client-side? Is it possible for the user to forge it? Would you suggest I do this on Smart Contact?

I can easily do these calculations on the client-side (using the TurfJS library) but since solidity does not support Float type and also due to the cost, it may not be a good idea to do these calculations on Smart Contact. what is your opinion?

in Smart Contract, Since Float variables are not supported, I have to store the lat/lon (polygon's coordinates) as String or UINT. I want to calculate the area of the selected polygon.


Solution

  • I would suggest making every necessary calculation off-blockchain since computing power is expensive and you have to always try making gas fees the lower as possible. Making those calculations client-side wouldn't be a bad idea if those calculations aren't manipulable for bad reasons.

    I hope you find this information useful.