0

I have a Token contract and I want to record the token price once per day. So I was thinking that to cut the trouble of going trough creating a server to save the data or using a service API I would just simply save the price of token once a day in a mapping:

mapping(uint256=> uint256) public dayTokenPrice;

Since the length of this mapping will be equal to days passed from creation of the contract it will never get that big. so even after 5 years it's length will be 365 * 5.

And in UI I will use this mapping data to create the price history of the token.

Mt question is if this is practical and would not create any problems that I'm not familiar with. my only concern is gas which wouldn't be that much since only one new item will be added to the mapping each day. Is there anything I'm missing here? what could go wrong?

1 Answer 1

0

If you don't really need the data on-chain, I strongly recommend not to store it on-chain because:

  1. Gas costs. It may be cheap enough now, but it may get more expensive in the future

  2. You need a process which updates the price. What if that process gets stuck or works wrong? What if the tx can't get through due to network congestion?

  3. How could anyone trust that the price is what you have stored? Or, if the data really isn't used on-chain, what's the point of having it there...

  4. Contracts should be as simple as possible. This adds unneeded complexity to your contract.

Otherwise data storage and retrieval shouldn't be an issue, as long as you use keys which make sense - you can't retrieve the data without the keys.

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.