Skip to content
LogoLogo

Named storage

Named domains live at ERC-7201 roots derived from their id strings. They never collide with each other or with the default record, and they survive upgrades and refactors.

named-storage.lithe
(* A named storage domain lives at an ERC-7201 root derived from its id, so
   its slots never collide with other domains and survive upgrades and
   refactors. The default `storage` record starts at slot 0, like Solidity. *)
 
import "std/evm";
 
storage is record {
  count : uint;
}
 
storage config at "example.config" is record {
  fee : uint;
  treasury : address;
}
 
storage stats at "example.stats" is record {
  volume : uint;
  users : map(address, bool);
}
 
(* A named domain is accessed by its name, not `storage.` *)
external function configure(const fee : uint; const treasury : address) is {
  config.fee := fee;
  config.treasury := treasury;
}
 
external function trade(const amount : uint) is {
  storage.count := storage.count + 1;
  stats.volume := stats.volume + amount;
  stats.users[Evm.sender()] := true;
}
 
external view function fee() : uint is
  config.fee

lithe storage named-storage.lithe prints each domain's root and slots:

config "example.config"
  root: 0x6169440e53b52b8b82649b9dc5d8cd0b3a6620a5608957f4eba1e677ed793300
  fee: uint256       slot 0
  treasury: address  slot 1, offset 0, 20 bytes