# How to store data on the blockchain and query it?

**URL:** <https://forum.algorand.co/t/how-to-store-data-on-the-blockchain-and-query-it/3950>\
**Category:** General\
**Created:** [August 6, 2021, 12:20pm UTC](https://forum.algorand.co/t/how-to-store-data-on-the-blockchain-and-query-it/3950 "2021-08-06T12:20:46Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![fabrice](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@fabrice](https://forum.algorand.co/u/fabrice)\
**Post date:** [August 6, 2021, 3:58pm UTC](https://forum.algorand.co/t/how-to-store-data-on-the-blockchain-and-query-it/3950/5 "2021-08-06T15:58:19Z")

</div>

> [@jacalf](#):
>
> What you are telling me, is that I would always keep the best bid on the contract global state right?
> 
> But how would I query the full 20.000 bids?

If you’re willing to do a bit of cryptography, you can have the smart contract store a cryptographic hash (e.g., SHA256) of the list of bids. This way you can have the indexer gets all the bids (as @danger_dave explained) only once, and store all the bids inside any storage (e.g., AWS S3).  
Then anyone can download the bids from the storage and check whether it matches the hash.  
The person uploading the bids to the S3 bucket does not need to be trusted: if they cheat, the hash will be invalid.  
(And if they cheat, you can always revert down to querying the indexer.)

To hash a list of bids, you can use the following process:

```plaintext
hash = SHA256(bid42 || SHA256(bid41 || SHA256(... || SHA256(bid1 || 0)))

```

Performance-wise, a usual computer can do at least 1M SHA256 hash of 64-byte values/s, so verification should take much less than one second.

Note: Maybe this solution is overkill and directly querying the indexer each time is good enough.

---

_[View the full topic](https://forum.algorand.co/t/how-to-store-data-on-the-blockchain-and-query-it/3950)._
