I have developed a SmartContract using ethereum which has an internal struct to store some of the privilege mapping. I find that whenever there is any change in the smart contract and the deployment is happening, the data is lost across upgrades.


contract PrivilegesContract is SuperAdminContract {

    struct Privilege {
        uint Id;
        string Name;

    uint private privilegeId;
    mapping(uint => string) private Privileges;

    function Add(string name) public EnsureSuperAdmin returns (uint) {
        Privileges[privilegeId] = name;
        privilegeId = privilegeId +1;
        return privilegeId;

Is there any persistent store that we can use so that i can retrieve the data after a new deployment or be unaffected by the deployments. If there is no persistent datastore, we should have a mechanism to read and initialize the data from the previous transactions in the block. Kindly share the behavior to be followed.


to quickly answer your question, no, data is not persistent across deployments, but we can make your data persistent in some cases:

Making a comparison with objects is a effective way to understand why this happens: you can have a car contract/object, when you deploy it, you are creating an instance of that car. Behaviour is really similar, you can have multiple instances of a car, and when you alter one of those instances, the rest, are not affected.

If keeping persistance is a requirement when the application is being used and not only on the development phase, I'd go for this solution:

Store that mapping into other smart contract, deploy it and access it from the other smart contracts like this:

PrivilegesContract privilegies = PrivilegesContract('0xContractAddress') 

string user = privilegies.Privileges[1];

That way, you are separating the data from the logic (all the functions) but the logic can still access the same data, if you redeploy the logic part of the smart contract you can access the same map.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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