NAME
Blockchain::Ethereum::Utils - Utility functions for Ethereum operations
VERSION
version 0.020
SYNOPSIS
use Blockchain::Ethereum::Utils;
# Convert human-readable values to wei
my $wei = parse_units('1.5', ETHER);
# Convert wei back to human-readable format
my $eth = format_units($wei, ETHER);
# Use unit constants for clarity
my $gwei_amount = parse_units('20', GWEI);
DESCRIPTION
This module provides utilities for Ethereum unit conversions. Currently focused on converting between different Ethereum denominations (wei, gwei, ether, etc.).
Additional Ethereum-related utilities may be added in future versions.
METHODS
parse_units
Converts a human-readable value to the smallest unit (wei equivalent)
$value- The numeric value to convert. Can be integer, decimal, or scientific notation$unit- The unit to convert from. Can be: - A unit constant: WEI, KWEI, MWEI, GWEI, SZABO, FINNEY, ETHER, ETH - A unit string: 'wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether', 'eth' - A number representing decimal places: 0-18
A string representation of the value in the smallest unit (wei equivalent)
parse_units('1.5', ETHER) # Returns '1500000000000000000'
parse_units('20', GWEI) # Returns '20000000000'
parse_units('100', 'mwei') # Returns '100000000'
parse_units('5.5', 6) # Returns '5500000'
format_units
Converts a value from the smallest unit (wei equivalent) to a human-readable format
$value- The value in smallest units to convert$unit- The unit to convert to. Same options as parse_units
A string representation of the formatted value with trailing zeros removed.
format_units('1500000000000000000', ETHER) # Returns '1.5'
format_units('20000000000', GWEI) # Returns '20'
format_units('100000000', 'mwei') # Returns '100'
format_units('5500000', 6) # Returns '5.5'
AUTHOR
REFECO <refeco@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2022 by REFECO.
This is free software, licensed under:
The MIT (X11) License