5

Variables used in contracts do they get stored in Blockchain?

If so does it require ether? If not how is persistent where is it stored?

6
  1. The variables you define could be persistent (stored in the contract storage) or volatile (stored in memory).

The global (state) variables are stored in 'storage' so they are in the blockchain. The function's parameters and return value are stored in the memory, and so are reseted after a function call.

e.g

contract C {
    uint256 id;
    function f(uint256 m) returns (uint256 r) {
        uint256 v; //pointer to storage
    }
}

id and v are in the storage.

m and r are in the memory.

However you can declare in solidity whether the variable should be stored in memory or in storage by using the keywords memory and storage;

e.g function f(uint[] storage _data, uint _value)

  1. When the variables are stored in the contract's storage, their size affects the contract call price, so you pay to store data in the blockchain. Read this answer to get an idea about storage cost: What is the cost to store 1KB, 10KB, 100KB worth of data into the ethereum blockchain?
2
  • thanks for the explanation, I checked the costing link, who bears that cost user is what I believe and isn't this expensive compared to other storage mechanisms? – Mighty Proton Nov 30 '16 at 12:35
  • indeed storing data in blockchain is expensive in comparison to other storage mechanism and the user is who pays to store data. – Badr Bellaj Nov 30 '16 at 12:52

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.