Skip to content
LogoLogo

Initialization

deploy runs once, as the contract is created, on the arguments passed with the deployment. It is Lithe's constructor.

initialization.lithe
(* `deploy` runs once, in the creation code, on the deployment's arguments. Nobody can
   call it later, so there is no "already initialized" flag to keep. *)
 
error CapIsZero;
 
storage is record {
  owner : address;
  cap : uint;
}
 
deploy(const owner : address; const cap : uint)
  raises CapIsZero
is {
  assert(cap > 0, CapIsZero);
  storage.owner := owner;
  storage.cap := cap;
}
 
external view function owner() : address is
  storage.owner
 
external view function cap() : uint is
  storage.cap
  • Deploy it like a Solidity contract: the arguments are ABI-encoded after the creation code, and the ABI has a constructor entry for them.
  • deploy can write storage and emit events, but cannot query or defer. See Deployment.
  • In an upgradeable contract, deploy initializes the proxy, as the proxy is created. Later versions set up new state with migrate.