Transient storage
Transient storage is shared by every call in a transaction and cleared when the transaction ends. Here a lender records an active loan that the borrower can read back during its callback.
transient-storage.lithe
(* Transient storage (EIP-1153) lasts for one transaction: shared by every call in
it, cleared when it ends, and cheap. It is read and written with TLOAD/TSTORE. *)
interface Callback is {
function onFlash(amount : uint);
}
error NotInFlash;
transient storage flash is record {
active : bool;
lent : uint;
}
storage is record {
totalLent : uint;
}
external function lend(const to : Callback; const amount : uint) is {
flash.active := true;
flash.lent := amount;
storage.totalLent := storage.totalLent + amount;
defer to.onFlash(amount);
}
(* Called back by the borrower during `lend`'s deferred call. *)
external view function currentLoan() : uint
raises NotInFlash
is {
assert(flash.active, NotInFlash);
} with flash.lent- Transient storage never appears in the storage layout or the upgrade layout.
- For locks, prefer
nonreentrant, which already uses transient storage.

