Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Tools for Crypto.org Chain wallet management and offline transaction signing

License

Notifications You must be signed in to change notification settings

crypto-org-chain/chainlibpy

Repository files navigation

🚨 DEPRECATED 🚨

This repo has been deprecated. You can generate protobuf code yourself or generate Python bindings directly from DeFi Wallet Core instead. Please reference that repository in the future.


Build Status codecov.io PyPI version Code style: black

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.

About

Tools for Crypto.org Chain wallet management and offline transaction signing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages