Store a mapping of 1 Mo of data

For some reasons, I’d like to store a static very big mapping of data inside a smart contract. It’s about 1 Mo of JSON data.

As it represent a lot of data, I’d be ready to pay more to be able to create this contract.

I would just like to know if this is possible on the Avalanche blockchain. Thanks for any reply.

1 Like

C-Chain has same gas limits as Ethereum, if I recall. Why not use IPFS, does it have to be directly in the contract itself?

Yes, it have to be directly in the contract, because it determines the behavior of the contract.

This mapping looks like a configuration JSON. If it would be impossible due to the gas limits in the C-Chain, maybe they could be another way, like another chain?

A well designed smart contract will contain the minimum required code and pointers to external data, thus separating your storage-layer from the public blockchain.

You could consider storing the data in a private blockchain or some other distributed storage. Last I used IPFS it was slow and clunky, but it may be worth another look.

Might be able to pull some ideas from this article, specifically the section titled The 3 Layers: The Blockchain:

1 Like

I had this same problem recently. You probably can’t initialize the contract with all the data pre-loaded because of the gas limit. There are two ways I came up with to handle it.

  1. Load the data in a series of contract calls. If you imagine the data you’re trying load is a big table, load X number of rows at a time until the whole table is loaded. This is pretty simple to implement and shouldn’t run into out of gas errors, but the downside is that it can be quite expensive. Definitely do some gas estimation before committing.

  2. Load your data into IPFS and use an oracle to query it as needed. This is probably the best way to handle it from a pricing/efficiency perspective. Our oracle of choice is ChainLink. We’re working on integrating them with our platform and they should be available to use within the next couple weeks. The downside to using an oracle is that ChainLink does not support this use case by default and you’d have to do some fiddling with their API to get it to work. However, I talked with their team about it and they said it would definitely be possible.

1 Like

I also like the idea of a new chain, but keep in mind, you need a new subnet for this new chain, so you will have to convince people to validate your subnet and load your new chain VM.

Thank you, really appreciate your answers. I think I will try first this way:

Load the data in a series of contract calls.