A lightweight converter for blockchain addresses supporting multiple formats
Project description
Address Converter
A lightweight Python library for converting blockchain addresses between different formats, with initial support for EVM-compatible chains and other blockchain networks.
Features
- Convert addresses between different blockchain formats
- Support multiple encoding formats (Base58Check, Hex)
- Comprehensive address validation
- Minimal dependencies (only
base58) - Type hints support
- Thoroughly tested
Installation
pip install address-converter
Quick Start
from address_converter import evm_to_tron, tron_to_evm, get_address_type
# Convert EVM format to alternative format
evm_address = "0x123456789abcdef123456789abcdef123456789a"
alt_base58 = evm_to_tron(evm_address, output_format='base58')
alt_hex = evm_to_tron(evm_address, output_format='hex')
print(f"Base58 format: {alt_base58}")
print(f"Hex format: {alt_hex}")
# Convert from alternative format to EVM
alt_address = "TJCnKsPa7y5okkXvQAidZBzqx3QyQ6sxMW"
evm_result = tron_to_evm(alt_address, add_prefix=True)
print(f"EVM format: {evm_result}")
# Detect address type
address_type = get_address_type(evm_address)
print(f"Address type: {address_type}") # 'evm'
API Reference
evm_to_tron(evm_address: str, output_format: str = 'base58') -> str
Convert an EVM address to alternative blockchain format.
- Parameters:
evm_address: EVM address (with or without '0x' prefix)output_format: Output format, either 'base58' or 'hex'
- Returns: Address in specified format
- Raises: ValueError if address is invalid
tron_to_evm(tron_address: str, add_prefix: bool = True) -> str
Convert an address from alternative blockchain format to EVM format.
- Parameters:
tron_address: Address in Base58Check or Hex formatadd_prefix: Whether to add '0x' prefix
- Returns: EVM address
- Raises: ValueError if address is invalid
get_address_type(address: str) -> Optional[str]
Detect address type.
- Parameters:
address: Address to detect
- Returns: Address type string ('evm', 'tron_base58', 'tron_hex') or None if invalid
Address Format Details
EVM Address
- 40 hexadecimal characters (excluding '0x' prefix)
- Case-insensitive
- Optional '0x' prefix
Alternative Address Formats
- Base58Check format: Specific prefix character, fixed length
- Hex format: Specific byte prefix, fixed length
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Technical References
- EVM Address Format
- Base58Check Encoding
- Various blockchain address format specifications
Support
If you have any questions or need help, please:
- Check the issues page
- Create a new issue if you can't find an answer
Star History
Disclaimer
This is an independent open-source project developed for educational and research purposes. It is not affiliated with, endorsed by, or connected to any organization or entity. The code is provided "as is" under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file address_converter-0.1.1.tar.gz.
File metadata
- Download URL: address_converter-0.1.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a2df6cdf86c9cf77dfccfe84c141c4ae7d8534df18ea4b259accb9831610755
|
|
| MD5 |
52839c6ff57a5f18b2ffe7ec5176f3c8
|
|
| BLAKE2b-256 |
679f6df062dab29e375f287e946202edbe9cd9b904f1e8d0631917cd386247cb
|
Provenance
The following attestation bundles were made for address_converter-0.1.1.tar.gz:
Publisher:
publish.yml on dongzhenye/address-converter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
address_converter-0.1.1.tar.gz -
Subject digest:
6a2df6cdf86c9cf77dfccfe84c141c4ae7d8534df18ea4b259accb9831610755 - Sigstore transparency entry: 314949520
- Sigstore integration time:
-
Permalink:
dongzhenye/address-converter@ad3c0c8f83c7ebb998792db562d36c082fff2109 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dongzhenye
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ad3c0c8f83c7ebb998792db562d36c082fff2109 -
Trigger Event:
release
-
Statement type:
File details
Details for the file address_converter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: address_converter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4eef2a00c21aa5c1285c8285141e414942528eb6fb1e534c3a084a9a96b58150
|
|
| MD5 |
a6f25712bd336cc6b8907a3cb60ebb99
|
|
| BLAKE2b-256 |
dadd5ef98b68278d76efcd1c94597679f9a8eb1bdde379e661faa7ee41fe0515
|
Provenance
The following attestation bundles were made for address_converter-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on dongzhenye/address-converter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
address_converter-0.1.1-py3-none-any.whl -
Subject digest:
4eef2a00c21aa5c1285c8285141e414942528eb6fb1e534c3a084a9a96b58150 - Sigstore transparency entry: 314949536
- Sigstore integration time:
-
Permalink:
dongzhenye/address-converter@ad3c0c8f83c7ebb998792db562d36c082fff2109 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dongzhenye
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ad3c0c8f83c7ebb998792db562d36c082fff2109 -
Trigger Event:
release
-
Statement type: