Python library and command line tool for converting cashaddr
Project description
ecashaddress
ecashaddress is python library which is able to convert legacy bitcoin addresses to the cashaddress format, and convert between various cashaddr prefixes.
It also provides a command line tool for converting address formats: ecashconvert
Installation
To install this library and its dependencies use:
pip install ecashaddress
Usage examples
As a library
The first thing you need to do is import the library via:
from ecashaddress import convert
from ecashaddress.convert import Address
Converting address
It does not matter if you use legacy or cashaddress as input.
Then you can convert your address via:
address = Address.from_string("155fzsEBHy9Ri2bMQ8uuuR3tv1YzcDywd4").to_cash_address()
or
address = Address.from_string("ecash:qqkv9wr69ry2p9l53lxp635va4h86wv435ugq9umvq").to_legacy_address()
You can convert between different CashAddr prefixes:
address = Address.from_string("ecash:qqkv9wr69ry2p9l53lxp635va4h86wv435ugq9umvq").to_cash_address(prefix="foobar")
Validating address
You can also validate address via:
convert.is_valid('155fzsEBHy9Ri2bMQ8uuuR3tv1YzcDywd4')
or
convert.is_valid('ecash:qqkv9wr69ry2p9l53lxp635va4h86wv435ugq9umvq')
Guessing a prefix
You can guess the prefix for a cash address. This only works for a short list of commonly used prefixes, such as “ecash”, “bitcoincash”, “simpleledger” or “etoken”.
convert.guess_prefix('qqkv9wr69ry2p9l53lxp635va4h86wv435ugq9umvq')
As a command line tool
When the library is installed with pip install ecashaddress, a command line tool is also installed. It should normally be installed in a location that is on your PATH, so you can run it from anywhere in a console:
ecashaddress --help
If this is not the case, an alternative is to run the library the following way:
python -m ecashaddress --help
This tool lets you convert one or more addresses to eCash addresses. It accepts as input addresses with legacy BTC format, or any valid CashAddr. By default, it outputs CashAddr with the ecash: prefix.
ecashaddress convert bitcoincash:qq3dmep4sj4u5nt8v2qaa3ea7kh7km8j05dhde02hg
To output a CashAddr with a different prefix, use the --prefix option:
ecashaddress convert bchtest:qq3dmep4sj4u5nt8v2qaa3ea7kh7km8j05f9f7das5 --prefix ectest
The tool also lets you guess the prefix from an address without prefix, if the prefix is in a short list of commonly used prefixes:
ecashaddress guessprefix qr4pqy6q4cy2d50zpaek57nnrja7289fksp38mkrxf
Development
Fork the repository on github.
Clone your fork of the repository.
Add the source repository as a remote.
git remote add upstream git@github.com:PiRK/ecashaddress.git git fetch upstream
Make sure your master branch is up-to-date with the upstream master.
git checkout master git pull upstream master
Create a local development branch, and add commits to it. Run the tests after each change, before git commit.
git checkout -b my_dev_branch # do your stuff python -m ecashaddress.tests.test git commit
Push you branch to your fork of the repository.
git push --set-upstream origin my_dev_branch
Create a pull request to the upstream repository.
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
File details
Details for the file ecashaddress-1.1.0.tar.gz
.
File metadata
- Download URL: ecashaddress-1.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da51e7cc90bb50945f603f501ceee44be8ae5cbc2ba48cac431f1d754256217d |
|
MD5 | 81f2f8a336bd26e00f63c055da718218 |
|
BLAKE2b-256 | 2225fd5fbdcf4977ab123493cbd429393ad8bdfe0c42384247870ef6ba311801 |