A collection of JavaScript utility functions for Rootstock.
@rsksmart/rsk-utils
is a library of utility functions designed to simplify working with the Rootstock blockchain ecosystem. It supports both CommonJS and ECMAScript Module (ESM) environments, making it versatile and easy to integrate into various projects.
- Supports CommonJS and ESM module systems.
- Utility functions for working with addresses, bytes, and blockchain-specific operations.
- TypeScript definitions included for better type safety.
- Lightweight and easy to use.
Install the library via npm:
npm install @rsksmart/rsk-utils
For CommonJS environments:
const rskUtils = require('@rsksmart/rsk-utils');
// Example usage
const { toChecksumAddress } = rskUtils;
console.log(toChecksumAddress('0x27b1FdB04752bBc536007a920D24ACB045561c26', 30));
For ECMAScript Module (ESM) environments:
import { toChecksumAddress } from '@rsksmart/rsk-utils';
console.log(toChecksumAddress('0x27b1FdB04752bBc536007a920D24ACB045561c26', 30));
Generates a checksummed address according to EIP-1191.
- Parameters:
address
(string): The address to checksum.chainId
(number | string): The chain ID for the network.
- Returns: A string representing the checksummed address.
Validates whether an address has a correct checksum for a specific chain ID.
- Parameters:
address
(string): The address to validate.chainId
(number | string): The chain ID used for checksum validation.
- Returns:
true
if the checksum is valid,false
otherwise.
Checks if a given string is a valid address.
- Parameters:
address
(string): The address to validate.
- Returns: true if valid, false otherwise.
Run the test suite to ensure the library works as expected:
npm run test
This will execute unit tests and display the results.
We welcome contributions to improve this library. Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Write clear commit messages and add tests for any changes.
- Submit a pull request with a detailed explanation of your changes.
This project is licensed under the MIT License. See the LICENSE file for details.
If you encounter any issues or have questions, feel free to open an issue on GitHub.