Tools for Crypto.org Chain wallet management and offline transaction signing
Project description
chainlibpy
Tools for Crypto.org Chain wallet management and offline transaction signing
Installing
Require Python >= 3.8, installing from PyPI repository:
pip install chainlibpy
Usage
Generating a wallet
from chainlibpy import Wallet
# create a wallet
wallet = Wallet.new()
# or you can recover from an mnomic
# mnemonic = "dune car envelope chuckle elbow slight proud fury remove candy uphold puzzle call select sibling sport gadget please want vault glance verb damage gown"
# wallet = Wallet(mnemonic)
print(wallet.private_key)
print(wallet.public_key)
print(wallet.address)
Signing and broadcasting a transaction
Please refer to example/transaction.py
for how to start a local testnet with pystarport
and change information below to run the examples successfully.
# Obtained from {directory_started_pystarport}/data/chainmaind/accounts.json
# To recover one of the genesis account
- MNEMONIC_PHRASE = "first ... last"
+ MNEMONIC_PHRASE = "REMEMBER TO CHANGE"
# Obtained from {directory_started_pystarport}/data/chainmaind/accounts.json
- TO_ADDRESS = "cro...add"
+ TO_ADDRESS = "REMEMBER TO CHANGE"
Interact with mainnet or testnet
Please refer to example/secure_channel_example.py
on how to use secure gRPC channel with server certificate to interact with mainnet or testnet.
Acknowledgement
Thanks to cosmospy for the following:
- referenced the packages to sign transaction and create hd wallet
- python lint config file
- use same sign method
Thanks to eth-utils for the following:
- Conversion of different units without facing precision issues in Python
Development
Set up development environment
Run command below to install dependencies (more about poetry):
poetry install
Add pre-commit git hook
To set up the git hook scripts, so that pre-commit
will run automatically on git commit
:
pre-commit install
Generate gRPC code
poetry shell
./generated_protos.sh
NOTE: By default, master
branch of cosmos-sdk
is used. Use command below to download a different version:
./generated_protos.sh -COSMOS_REF=v0.44.5
If more generated gRPC code is needed in the future, please add the path to .proto
file needed here in generated_protos.sh
:
# Add .proto files here to generate respective gRPC code
PROTO_FILES="
$COSMOS_SDK_DIR/proto/cosmos/auth/v1beta1/auth.proto
+$COSMOS_SDK_DIR/proto/other.proto
...
Tox
Tox is a tool to automate and standardize testing processes in Python.
For this project, the list of environment that will be run when invoking tox
command is py{38,39}
. Hence we need to set up Python 3.8 and 3.9 for this project. Run command below to set a local application-specific Python version (in this case 3.8 and 3.9) with pyenv:
pyenv local 3.8.a 3.9.b
Note: a
and b
are python versions installed on your computer by pyenv
.
After running command above, a .python-version
file will be generated, which means python versions inside .python-version
are presented for this project. Now, running command tox
should succeed without prompting environment missing error.
Run command below to verify:
poetry run tox
# or
poetry shell
tox
It is also recommended to run tox
command before pushing a commit.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for chainlibpy-3.0.0-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb216ae92ec83a1e130b2006818ddade7474ca59a543c8017feedc2581f68981 |
|
MD5 | 1ca19cbcba0ec7f533052f7cd096f6b1 |
|
BLAKE2b-256 | 4dc962cee1c68bd2b81efe158a4096e686531561e001519fad7c63a23cc2abbe |