Skip to main content

cfx-address

Conflux base32 address utilities

Full documentation -> https://conflux-fans.github.io/cfx-address/cfx_address.html#module-cfx_address

installation

pip install cfx-address

use Base32Address class methods

from cfx_address import Base32Address

validate a base32 address

Base32Address.is_valid_base32("0x1ecde7223747601823f7535d7968ba98b4881e09") 
# False
Base32Address.validate("0x1ecde7223747601823f7535d7968ba98b4881e09")
# will raise an exception

encode and decode

# encode hex address to base32
Base32Address.encode_base32("0x1ecde7223747601823f7535d7968ba98b4881e09", network_id=1)
#'cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4'

# decode base32 address
Base32Address.decode("cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4")
# result:
# {'network_id': 1,
# 'hex_address': '0x1ecde7223747601823f7535d7968ba98b4881e09',
# 'address_type': 'user'}

utilities

address_str = "cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4"
address_verbose_str = "CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4"
assert Base32Address.equals(address_str, address_verbose_str)

Base32Address.calculate_mapped_evm_space_address(address_str)
Base32Address.zero_address(network_id=1)
Base32Address.shorten_base32_address(address_str)

Base32Address instances

instance initialization

address = Base32Address("cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4")
# 'cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4'

# Base32Address inherits from str
assert isinstance(address, str)

# init from hex address, in which case network_id is required
Base32Address("0x1ecde7223747601823f7535d7968ba98b4881e09", network_id=1029)
# 'cfx:aatp533cg7d0agbd87kz48nj1mpnkca8be7ggp3vpu'

# change a base32 address to other network
Base32Address(address, network_id=1029)
# 'cfx:aatp533cg7d0agbd87kz48nj1mpnkca8be7ggp3vpu'

# verbose option defaults to False
Base32Address(address, verbose=True)
# 'CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4'

eq and properties

# __eq__ is implemented, address in same network is treated equal
assert address == "cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4"
assert address == "CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4"
assert "CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4" == address
assert "cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4" == address

# address in different network is not equal
mainnet_address = Base32Address(address, 1029)
assert mainnet_address == "cfx:aatp533cg7d0agbd87kz48nj1mpnkca8be7ggp3vpu"
assert not address == mainnet_address

# properties
[
    address.address_type,
    address.network_id,
    address.hex_address,
    address.verbose_address,
    address.short,
    address.mapped_evm_space_address
]
# ['user',
#  1,
#  '0x1ECdE7223747601823f7535d7968Ba98b4881E09',
#  'CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4',
#  'cfxtest:aat...95j4',
#  '0x349f086998cF4a0C5a00b853a0E93239D81A97f6',
#  ]

Metadata

Release files for cfx-address 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cfx-address 1.0.1
File Size Uploaded
cfx-address-1.0.1.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cfx-address 1.0.1
File Interpreter ABI Platform
cfx_address-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 28.4 kB

Release files / cfx-address-1.0.1.tar.gz

Download URL cfx-address-1.0.1.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c7441c4108584cb4e9d46e131b3d7545fb6f2bd5c4106ccd5013384828973ef9
BLAKE2b-256 checksum
How to use checksums
f47df1ab5b0b193939a5239dda8418c0ceadc68416df2935665702a3bcb8cc9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.17

Release files / cfx_address-1.0.1-py3-none-any.whl

Download URL cfx_address-1.0.1-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bd1185e036c47d6bcc24ef8f08ea74511cd39d1f049c179be56a3bfc0af66a7
BLAKE2b-256 checksum
How to use checksums
c612365cf95c65b4dd069e6ad101dc3852492adb2aab5d0a61ea843b4c0ffbc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.17
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page