A lightweight JavaScript library to validate Solidity data types like int, uint, bytes, and Ethereum-specific types such as addresses and transaction hashes.
- Validate signed and unsigned integers (
int,uint) with customizable bit sizes. - Validate Solidity
bytestypes (1, 2, 4, 8, 16, 32). - Validate Ethereum addresses and transaction hashes.
- Provides simple and easy-to-use functions.
To install the library, run the following command:
npm install sol-type-checkYou can import the library in your project like this:
const { isInt, isUint, isBytes, isAddress, isHash } = require('sol-type-check');Checks if a value is a signed integer within the range for a given bit size.
isInt(32, 123); // true
isInt(8, -130); // falseChecks if a value is an unsigned integer within the range for a given bit size.
isUint(32, 4294967295); // true
isUint(8, -1); // falseChecks if a value is a valid bytes array of the specified size.
isBytes(4, "0xabcdef"); // true
isBytes(2, "0x12345"); // falseChecks if a value is a valid Ethereum address.
isAddress("0x32Be343B94f860124dC4fEe278FDCBD38C102D88"); // true
isAddress("0xInvalidAddress"); // falseChecks if a value is a valid Ethereum transaction hash.
isHash("0x5c504ed7d413568f857eeb70f9f70e0d8b6b7469c9a7f325d9776de08e850635"); // true
isHash("0xInvalidHash"); // false-
isInt(bits, value)
Validates a signed integer for the specified bit size.bits: An integer (8, 16, 32, 64, 128, or 256) representing the bit size.value: A number to check if it is within the valid range.
-
isUint(bits, value)
Validates an unsigned integer for the specified bit size.bits: An integer (8, 16, 32, 64, 128, or 256) representing the bit size.value: A number to check if it is within the valid range.
-
isBytes(bytes, value)
Validates a bytes array of a specified size.bytes: An integer (1, 2, 4, 8, 16, or 32) representing the expected byte size.value: A string representing the bytes in hexadecimal format (prefixed with0x).
-
isAddress(value)
Validates an Ethereum address.value: A string representing the Ethereum address (must start with0xand be 40 hexadecimal characters).
-
isHash(value)
Validates an Ethereum transaction hash.value: A string representing the Ethereum transaction hash (must start with0xand be 64 hexadecimal characters).
If you would like to contribute to this project, feel free to fork the repository and create a pull request. We welcome bug reports, suggestions, and improvements.
If you encounter any issues or have questions, please open an issue in this repository or contact us at rakawidhiantoro@gmail.com.
This project is licensed under the MIT License - see the LICENSE file for details.