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.2.4

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.2.4
File Size Uploaded Provenance Actions
cfx_address-1.2.4.tar.gz 14.4 kB Without provenance Details for cfx_address-1.2.4.tar.gz

Built distribution (wheel)

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

Total release size: 28.9 kB

Release files / cfx_address-1.2.4.tar.gz

Download URL cfx_address-1.2.4.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7fd3e1154ed922117305c14eb2157e2f3cfb36b73403671e32840836f25f6526
BLAKE2b-256 checksum
How to use checksums
056a140ae9a62b3b9f7dfb06d8625466374f23cf3c038cd815b492c09ad2784b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

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

Download URL cfx_address-1.2.4-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7aeeb7963edca6e65f8586c7187a1159a8f61fd8d7a156d80cc5351bcc509ab3
BLAKE2b-256 checksum
How to use checksums
88f15620114f0b920027982bfc0d15b00f82765238bc8bc38c818c14c685b2cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Security for cfx-address 1.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2.4 This release

2 release files No provenance

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