https://github.com/zororaka00/sol-type-check
A lightweight JavaScript library to validate Solidity data types like int, uint, bytes, and Ethereum-specific types such as addresses and transaction hashes.
https://github.com/zororaka00/sol-type-check
ethereum javascript library smart-contract solidity type-check typescript web3
Last synced: 4 months ago
JSON representation
A lightweight JavaScript library to validate Solidity data types like int, uint, bytes, and Ethereum-specific types such as addresses and transaction hashes.
- Host: GitHub
- URL: https://github.com/zororaka00/sol-type-check
- Owner: zororaka00
- License: mit
- Created: 2024-11-24T14:20:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-27T11:24:28.000Z (over 1 year ago)
- Last Synced: 2025-10-10T03:36:53.585Z (8 months ago)
- Topics: ethereum, javascript, library, smart-contract, solidity, type-check, typescript, web3
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/sol-type-check
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# sol-type-check
A lightweight JavaScript library to validate Solidity data types like `int`, `uint`, `bytes`, and Ethereum-specific types such as addresses and transaction hashes.
## Features
- Validate signed and unsigned integers (`int`, `uint`) with customizable bit sizes.
- Validate Solidity `bytes` types (1, 2, 4, 8, 16, 32).
- Validate Ethereum addresses and transaction hashes.
- Provides simple and easy-to-use functions.
## Installation
To install the library, run the following command:
```bash
npm install sol-type-check
```
## Usage
### Importing the Library
You can import the library in your project like this:
```javascript
const { isInt, isUint, isBytes, isAddress, isHash } = require('sol-type-check');
```
### Example Functions
#### `isInt(bits, value)`
Checks if a value is a signed integer within the range for a given bit size.
```javascript
isInt(32, 123); // true
isInt(8, -130); // false
```
#### `isUint(bits, value)`
Checks if a value is an unsigned integer within the range for a given bit size.
```javascript
isUint(32, 4294967295); // true
isUint(8, -1); // false
```
#### `isBytes(bytes, value)`
Checks if a value is a valid bytes array of the specified size.
```javascript
isBytes(4, "0xabcdef"); // true
isBytes(2, "0x12345"); // false
```
#### `isAddress(value)`
Checks if a value is a valid Ethereum address.
```javascript
isAddress("0x32Be343B94f860124dC4fEe278FDCBD38C102D88"); // true
isAddress("0xInvalidAddress"); // false
```
#### `isHash(value)`
Checks if a value is a valid Ethereum transaction hash.
```javascript
isHash("0x5c504ed7d413568f857eeb70f9f70e0d8b6b7469c9a7f325d9776de08e850635"); // true
isHash("0xInvalidHash"); // false
```
## API
- **`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 with `0x`).
- **`isAddress(value)`**
Validates an Ethereum address.
- **`value`**: A string representing the Ethereum address (must start with `0x` and be 40 hexadecimal characters).
- **`isHash(value)`**
Validates an Ethereum transaction hash.
- **`value`**: A string representing the Ethereum transaction hash (must start with `0x` and be 64 hexadecimal characters).
## Contributing
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.
## 🛠Support
If you encounter any issues or have questions, please open an issue in this repository or contact us at rakawidhiantoro@gmail.com.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.