benjamin0000 / ethereum-address-validator
Validate etheruem address
dev-main
2021-11-11 10:17 UTC
Requires
- php: >=7.1
- kornrunner/keccak: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2025-03-11 17:36:10 UTC
README
(c) by Benjamin Odiowa benen250@gmail.com
License
MPL-2.0
Brief
Class that verifies if Ethereum address is properly formatted and - optionaly - properly checksummed according to EIP-55.
Installation
Use composer:
composer require benjamin0000/ethereum-address-validator
Usage
<?php use \Benji\Ethereum\AddressValidator; // Addresses that have good format and checksum are considered valid AddressValidator::isValid('0xA477941c7AAD6536f175ef123bf9eeD6F82A4c85') === AddressValidator::ADDRESS_VALID; // Also addresses that are all uppercase or all lowercase are considered valid (no checksum check performed) AddressValidator::isValid('0xA477941C7AAD6536F175EF123BF9EED6F82A4C85') === AddressValidator::ADDRESS_VALID; AddressValidator::isValid('0xa477941c7aad6536f175ef123bf9eed6f82a4c85') === AddressValidator::ADDRESS_VALID; // Addresses that have good format but incorrect checksum AddressValidator::isValid('0xA477941c7aaD6536f175ef123bf9eeD6F82A4c85') === AddressValidator::ADDRESS_CHECKSUM_INVALID; // Address without proper format return AddressValidator::isValid('invalid address') === AddressValidator::ADDRESS_INVALID; // To get canonical (properly checksummed) addres, use: AddressValidator::getCanonicalAddress('0xA477941C7AAD6536F175EF123BF9EED6F82A4C85') === '0xA477941c7AAD6536f175ef123bf9eeD6F82A4c85'