How to export out wallet addresses and ERC721 token ownership map from a solidity contract?

I am looking to export this map outside of the contract at anytime as a snapshot then import it into a different contract.

1 Answer 1


You can't really do that, unless you have all the keys or it's your contract and you implement a functionality like that.

Here a couple of approaches:

You can either create a logic in the contract to return/export all the data from a mapping. For that, the contract will need to hace an arrays of keys that it uses to save all the keys when a new element is added to the mapping, and removed when an element is removed from the mapping.

Then, you just need to create a function that loops through that array and for each key it goes getting the value in the mapping, saving them in a memory array of those values and returning them after de loop.

If it's not your contract or you don't want to implement a logic like that, then your other option is to have all the keys anyways, then call the getter function of the mapping in a loop with each of the keys.

If there's no public/external getter function for the mapping, then you need to get the values of each key directly from storage with something like:

wev3.eth.getStorageAt(contractAddress, storageIndexForEachKey);

to get the values directly from the storage of the contract.

Here you can learn how to access the storage directly, for arrays, mappings, etc: https://coinsbench.com/solidity-layout-and-access-of-storage-variables-simply-explained-1ce964d7c738

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.