Insert a mapping data from Contract A to contract B

Hi!

I have to create a new contract because we would like to add a new feature. Is it possible to get all the mapping data from the first contract to the new one?

If so, what’s the best way to do it? I am thinking about changing the Mapping to Array in the new contract so I can just put all the keys to it along side with the data.

you can query the old contract to get that mapping?

is there a way to stop/disable the old contract?

No, there’s no stop/disable. That’s why we want to import it to the new contract.

maybe you can query the contract to get that mapping info (from the new contract of offline to get a snapshot)

or you can also check all the events for that old contract offline to get a snapshot in case that there are events that can be processed

Yes, I have the database for the events of the previous contract. But we also want to put everything in the final contract. Is there any other way to this? Thank you for the help btw :slight_smile: Really appreciate it.

you can call a function from the new contract in the old contract or you can call a function in the new contract to initialise that mapping with the data that you have off chain

What do you mean by this?

you create a function in the new contract that you can use to initialise the mapping, and you call it few times in order to add all the elements in that mapping, and you enable that function only for the contract owner or contract admin

Ahh yes, that was also what I’m thinking, but my issue is that there’s around 200 transactions in the first contract. Would that cost me a lot to repopulate the new mapping?

So that’s why I’m thinking about changing the mapping to array to push all previous data in an array list.

it depends on how much data it is, you don’t have to make the same 200 transactions, you can set the same data with fewer transactions or with one transaction if it is not too much data to set in that mapping