Skip to content

Instantly share code, notes, and snippets.

@Zer0dot
Zer0dot / ImmutableStrings.sol
Last active January 17, 2023 22:22
A library with a custom type to introduce immutable strings of length less than 32 bytes.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
/**
* @title ImmutableStringLib
* @author Zer0dot
*
* @notice This library introduces an abstraction to store and decode immutable strings.
* This is necessary because simply casting a string to a bytes32 variable will lose the
* length, which will be hardcoded as 32 upon re-converting via abi.encode.