TransientSlot
Overview
License: MIT
library TransientSlotLibrary for reading and writing value-types to specific transient storage slots.
Transient slots are often used to store temporary values that are removed after the current transaction. This library helps with reading and writing to such slots without the need for inline assembly.
Example reading and writing values using transient storage:
contract Lock {
using TransientSlot for *;
// Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
modifier locked() {
require(!_LOCK_SLOT.asBoolean().tload());
_LOCK_SLOT.asBoolean().tstore(true);
_;
_LOCK_SLOT.asBoolean().tstore(false);
}
}TIP: Consider using this library along with {SlotDerivation}.
Functions info
asAddress
Cast an arbitrary slot to a AddressSlot.
asBoolean
Cast an arbitrary slot to a BooleanSlot.
asBytes32
Cast an arbitrary slot to a Bytes32Slot.
asUint256
Cast an arbitrary slot to a Uint256Slot.
asInt256
Cast an arbitrary slot to a Int256Slot.
tload
Load the value held at location slot in transient storage.
tstore
Store value at location slot in transient storage.
tload
Load the value held at location slot in transient storage.
tstore
Store value at location slot in transient storage.
tload
Load the value held at location slot in transient storage.
tstore
Store value at location slot in transient storage.
tload
Load the value held at location slot in transient storage.
tstore
Store value at location slot in transient storage.
tload
Load the value held at location slot in transient storage.
tstore
Store value at location slot in transient storage.
Last updated