Smart Contract Storage – Where Are the Variables of a Smart Contract Stored?

blockchaingo-ethereumsolidity

we all know that we can write smart contract with solidity in ethereum such as:

 mapping(bytes32 => bytes32) private  userPasswds ;
    event RecordReturnResult(bool res);

    /// @dev new the pair of user and password to the array here
    function newPair(string user, string password)  returns (bool) {      
        bytes32  sha3_user = sha3(user);
        bytes32  sha3_password = sha3(password);
        bool res = true;
        if (userPasswds[sha3_user] > 0) {
            res = false;
            RecordReturnResult(res);
            return res;
        }           
        else{
            userPasswds[sha3_user] = sha3_password;
            res = true;
            RecordReturnResult(res);
            return res;
        }      
    }

Where are the variables stored? For example:

    mapping(bytes32 => bytes32) private  userPasswds ;
    event RecordReturnResult(bool res);bytes32  sha3_user = sha3(user);
    bytes32  sha3_password = sha3(password);
    bool res = true;

are they stored in block chain or leveldb or other places? thank you.

Best Answer

these states are stored in the Contract's storage. Each contract has its own storage and memory space and both are in the blockchain(leveldb physically).

look at the diagram below to get an idea :

enter image description here

Related Topic