Efficiently storing Up to 4 million bits in a TON smart contract
from Jeff

I'm working on a TON smart contract that may need to store up to 4 million bits. I understand from the TON documentation that this isn't typically recommended, but I'm exploring the possibility for extreme cases.

Given that a cell can hold up to 1023 bits, I'd need roughly 4 million / 1023 ā‰ˆ 4000 cells to store all the bits.

My initial idea is to employ a data structure that uses a dictionary. This dictionary would have up to 4,000 keys, with each key mapping to a cell containing 1023 bits.

Another approach I'm considering is leveraging the fact that a cell can reference up to four other cells. So, starting with four reference cells in my contract, I could keep expanding the depth of each cell hierarchy to store the full 4 million bits.

In most scenarios, my contract will likely use no more than 10,000 bits. But I want to be prepared for cases where it could expand to the full 4 million bits. Considering that, once stored, the data will mostly be accessed for reading (rather than frequent updates), what would be the most efficient way to structure the storage?



šŸ”— Answer on TON Overflow

Aug 24, 2023, 1:11 PM

Ā© 2024 Draquery.com All rights reserved.