The documentation is outdated and will be updated as soon as possible
@safeblock/blockchain-utils
provides tools and utilities for managing blockchain networks, addresses, amounts, and providers with seamless integration and ease of use. Built for developers working in blockchain ecosystems, it includes functionalities to manage networks, validate and process addresses, handle amounts effectively, and utilize fallback providers.
- Network Management: Pre-configured support for blockchain networks.
- Address Utilities: Includes type checks, actions, and support for special addresses.
- Amount Utilities: Provides robust tools for amount calculations, formatting, and validation.
- Provider Integration: Simplifies interactions with public nodes using a fallback mechanism.
- Provider Reconfiguration: Dynamically update the provider list as needed.
- Extensible: Modular design for easy customization and integration.
Install the package via npm:
npm install @safeblock/blockchain-utils
or via yarn:
yarn add @safeblock/blockchain-utils
import { networks } from '@safeblock/blockchain-utils';
console.log(networks);
import { isSpecialAddress, validateAddress } from '@safeblock/blockchain-utils/address';
const address = '0x...';
// Check if an address is special
console.log(isSpecialAddress(address));
// Validate the address format
console.log(validateAddress(address));
The Address Utilities module also supports:
- Address Type Checks: Easily determine if an address is valid or matches specific criteria.
- Address Actions: Includes functions for address formatting and manipulation.
import { parseAmount, formatAmount } from '@safeblock/blockchain-utils/amount';
// Parse an amount string to a standardized object
const parsedAmount = parseAmount('1.23');
console.log(parsedAmount);
// Format an amount object for display
const formattedAmount = formatAmount(parsedAmount);
console.log(formattedAmount);
The Amount Utilities module supports:
- Parsing amounts from strings into objects.
- Formatting amounts for user-friendly display.
- Validating amounts to ensure accuracy.
import { createFallbackProvider, reconfigureProviders } from '@safeblock/blockchain-utils/ethers-provider';
// Create a fallback provider with a list of nodes
const provider = createFallbackProvider(['https://mainnet.infura.io', 'https://cloudflare-eth.com']);
// Dynamically update the provider list
reconfigureProviders(provider, ['https://new-node1.com', 'https://new-node2.com']);
The Ethers Provider module supports:
- Fallback mechanisms for reliable provider access.
- Reconfiguring provider lists dynamically without restarting the application.
networks
: Pre-defined blockchain network configurations.index
: Main entry point to the package.
selectAddress
: Helps select and validate blockchain addresses.cast
: Handles type conversions.
specialAddresses
: Defines special address types and checks.addressActions
: Perform actions such as validations and formatting.
parseAmount
: Converts string representations of amounts into structured objects.formatAmount
: Formats structured amounts for user-friendly display.
publicNodesList
: Lists pre-configured public nodes for network access.createFallbackProvider
: Ensures reliable provider access by using fallback mechanisms.reconfigureProviders
: Dynamically updates the provider list for runtime flexibility.
We welcome contributions! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature-branch-name
. - Make your changes and commit them:
git commit -m 'Add new feature'
. - Push the changes:
git push origin feature-branch-name
. - Submit a pull request.
This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
For more information, visit: CC BY-NC-SA 4.0.