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 working with address formats.
To install this library and its dependencies use:
pip install ecashaddress
The first thing you need to do is import the library via:
from ecashaddress import convert
from ecashaddress.convert import Address
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")
You can also validate address via:
convert.is_valid('155fzsEBHy9Ri2bMQ8uuuR3tv1YzcDywd4')
or
convert.is_valid('ecash:qqkv9wr69ry2p9l53lxp635va4h86wv435ugq9umvq')
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')
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
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.