简体   繁体   中英

How is state data stored on Ethereum blockchain?

Was thinking about storage costs on Ethereum and trying to comprehend the implication of storing a globally standardized credit score (like Bloom) on-chain.

In the simplest case, you would store three 256bit words of data per user, indexed by user addresses, which would mean 4 words of storage.

In the scenario where you reached 100M users, you are looking at 400M words of storage, total. Each word of storage on the Ethereum blockchain requires 20K in gas fees, so with even 1 gwei at the current price of $1147/ETH, you are looking at ~$9.4M to store all credit scores of the user base.

So, my question is thus:

If you change the state of the contract above by updating one user's score, does it require storing the entire 400M words of data again (and incurring the $9.4M charge), or is only a delta of the state stored in some metadata layer?

Unless you're changing the order of records (by removing one of them, for example), you won't have to overwrite the whole array. You'll only pay gas for data that you add or update.

In short, you wouldn't be storing that information directly on the Ethereum blockchain. You would use IPFS.

Basically, you store any file into IPFS and then you store the IPFS hash in the Ethereum contract. Any user with an IPFS node is going to be able to access the file using that hash. You can store data, images, the front end, etc. whatever you want.

Here you have an example: https://github.com/AdrianClv/ethereum-ipfs

Finally, where should I store my data?

Well, maybe not on the Ethereum Blockchain. The data stored there, with Smart Contracts, is safe and easy to access. But the cost and the structure of the store makes it relevant for metadata-related uses.

Taking the examples from the introduction: Users Posts, Files and Message Boxes will probably be on another platform like IPFS. In the Ethereum Blockchain, we would store critical data. Data like encryption keys, roots to storage trees & authorizations.

Source: https://www.lsenta.io/posts/storage-and-dapps-on-ethereum-blockchain/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM