Encodes and decodes address formats for various cryptocurrencies
Project description
address-encoder
Encodes and decodes address formats for various cryptocurrencies. Converts addresses between human-readable text and their native binary representations for use with EIP-2304 and ENS multichain resolution.
Source: github.com/ensdomains/address-encoder-py
EVM compatible chains are either specified using SLIP-44 coin type or 0x80000000 | chainId where 0x80000000 is the MSB (most significant bit) reserved at SLIP-44 and no coin types exist in that range. This is to avoid number collision with the existing coin types.
See ENSIP-11 for more detail.
Installation
pip install address-encoder
Available on PyPI.
For local development:
pip install -e ".[dev]"
Usage
from address_encoder import get_coder_by_coin_name
btc = get_coder_by_coin_name("btc")
decoded = btc.decode("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa")
encoded = btc.encode(decoded)
Hex input
Encoders expect bytes. Convert hex strings with the utility helpers:
from address_encoder import get_coder_by_coin_name
from address_encoder.utils import hex_to_bytes
btc = get_coder_by_coin_name("btc")
address = btc.encode(hex_to_bytes("0x76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac"))
Direct coin imports
from address_encoder.coins.btc import btc
decoded = btc.decode("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa")
EVM chains
Many EVM chains are supported, but none of them (except ETH) are exported from address_encoder.coins. To encode or decode addresses for an EVM chain, use the ETH codec via get_coder_by_coin_name:
from address_encoder import get_coder_by_coin_name
op = get_coder_by_coin_name("op") # Optimism
decoded = op.decode("0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb")
You can also look up a codec by coin type:
from address_encoder import get_coder_by_coin_type
op = get_coder_by_coin_type(2147483658) # 0x80000000 | 10
Development
pytest
Maintainer scripts
Interactive helpers for adding coins and keeping docs in sync:
python3 scripts/generate_coin.py # scaffold a new non-EVM coin module and test
python3 scripts/add_evm_coin.py # add EVM chain entries to coin maps
python3 scripts/format_supported_coins.py # regenerate docs/supported-cryptocurrencies.md
python3 scripts/prepublish_only.py # run tests and verify the wheel builds
Coin types
When adding a new coin, the coin type is a numeric identifier from SLIP-44. It must be an integer, not a coin name or symbol.
| Chain type | Coin type | Script |
|---|---|---|
| Non-EVM (e.g. BTC, SOL) | SLIP-44 index (e.g. 0 for Bitcoin, 501 for Solana) |
scripts/generate_coin.py |
| EVM (e.g. Optimism, Base) | Computed as 0x80000000 | chainId — enter the chain ID only |
scripts/add_evm_coin.py |
If the coin is not listed in SLIP-44, open a PR to add it there first.
Package layout
address_encoder— main API (get_coder_by_coin_name,get_coder_by_coin_type)address_encoder.coins— per-coin codecsaddress_encoder.coders— per-coin encode/decode function exportsaddress_encoder.consts— SLIP-44 and EVM chain mappingsaddress_encoder.utils— shared encoding primitives
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_encoder-1.0.2.tar.gz.
File metadata
- Download URL: address_encoder-1.0.2.tar.gz
- Upload date:
- Size: 63.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
977a078ab31d7565f2a42dc03d32dc1523459bd1c1e2ec44e75dd3169f1b23aa
|
|
| MD5 |
ad999e86e8fbd653e59e9cba90514278
|
|
| BLAKE2b-256 |
fa3d9662260d64b0c0f0960be72a6ce6d43d9bd7b0b8f50dfdc392c0e72b0d90
|
Provenance
The following attestation bundles were made for address_encoder-1.0.2.tar.gz:
Publisher:
publish.yml on ensdomains/address-encoder-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
address_encoder-1.0.2.tar.gz -
Subject digest:
977a078ab31d7565f2a42dc03d32dc1523459bd1c1e2ec44e75dd3169f1b23aa - Sigstore transparency entry: 2034931072
- Sigstore integration time:
-
Permalink:
ensdomains/address-encoder-py@a4f1dfc255f59818b180899951ae3ac68ab674a3 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/ensdomains
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a4f1dfc255f59818b180899951ae3ac68ab674a3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file address_encoder-1.0.2-py3-none-any.whl.
File metadata
- Download URL: address_encoder-1.0.2-py3-none-any.whl
- Upload date:
- Size: 79.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c51424bc521f6195fcd7c430e807568e564699d727a331ce0a9f7374d959c93a
|
|
| MD5 |
1bfacdc608d4892f41688b653b0df899
|
|
| BLAKE2b-256 |
f14ca721a8f7a4ee8c888e7b3308a3d28ea91da08084bd836d9662b1f8483a0a
|
Provenance
The following attestation bundles were made for address_encoder-1.0.2-py3-none-any.whl:
Publisher:
publish.yml on ensdomains/address-encoder-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
address_encoder-1.0.2-py3-none-any.whl -
Subject digest:
c51424bc521f6195fcd7c430e807568e564699d727a331ce0a9f7374d959c93a - Sigstore transparency entry: 2034931318
- Sigstore integration time:
-
Permalink:
ensdomains/address-encoder-py@a4f1dfc255f59818b180899951ae3ac68ab674a3 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/ensdomains
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a4f1dfc255f59818b180899951ae3ac68ab674a3 -
Trigger Event:
release
-
Statement type: