Are Solidity mappings stored in memory or storage?

I know that keys are hashed to a unique identifier for the value, which is stored where?

I can't seem to find any clue in the documentation.

1 Answer 1


They will be in storage as memory should be cleared after each transaction. So if a mapping was anything but storage it would not persist. Anything defined within the scope of a contract will be stored in that contract's storage.

What is the memory keyword? What does it do? The Ethereum Virtual Machine has three areas where it can store items.

The first is “storage”, where all the contract state variables reside. Every contract has its own storage and it is persistent between function calls and quite expensive to use.

The second is “memory”, this is used to hold temporary values. It is erased between (external) function calls and is cheaper to use.

The third one is the stack, which is used to hold small local variables. It is almost free to use, but can only hold a limited amount of values.

See http://solidity.readthedocs.io/en/latest/frequently-asked-questions.html#what-is-the-memory-keyword-what-does-it-do

Here's the proof of work Ethereum Blockchain Mechanism

enter image description here

Also see Where are the variables of a smart contract stored?

  • How do I clear all allocated storage associated with a mapping?
    – Shuzheng
    Sep 21, 2017 at 6:30
  • 1
    You would have to iterate over all the keys of the mapping and execute delete on each item. So, for example if you were doing this for addresses you would need an array of keys to iterate over. Trying to execute a delete on the mapping would yield no effect as per the docs solidity.readthedocs.io/en/develop/types.html Sep 21, 2017 at 9:20

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.