Skip to main content

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.

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

Coming soon to PyPI. In the meantime, install from source.

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 codecs
  • address_encoder.coders — per-coin encode/decode function exports
  • address_encoder.consts — SLIP-44 and EVM chain mappings
  • address_encoder.utils — shared encoding primitives

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

address_encoder-1.0.0rc3.tar.gz (63.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

address_encoder-1.0.0rc3-py3-none-any.whl (79.1 kB view details)

Uploaded Python 3

File details

Details for the file address_encoder-1.0.0rc3.tar.gz.

File metadata

  • Download URL: address_encoder-1.0.0rc3.tar.gz
  • Upload date:
  • Size: 63.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for address_encoder-1.0.0rc3.tar.gz
Algorithm Hash digest
SHA256 dfbb7d76f378a8fa02060a0e2331b76232dd0e0fffeccfa455f885e5fbdebfe2
MD5 2d976827a537e2c37ced587b4572eba1
BLAKE2b-256 1563b55af42c305d07474e9eaf21905c73168caaf23d67f4462d432a25f8e9a3

See more details on using hashes here.

File details

Details for the file address_encoder-1.0.0rc3-py3-none-any.whl.

File metadata

File hashes

Hashes for address_encoder-1.0.0rc3-py3-none-any.whl
Algorithm Hash digest
SHA256 9113f1ebd0cd10cbfab689af66e2f8adf7b4cab4c046ae94fd272fafa6edfbcb
MD5 f622c846883c4e3dbd8913cade5c021a
BLAKE2b-256 b88fde002375a335c72f380d6360bdb6ebe5975b228cfa6dfdae0f3e137ccd92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page