Skip to content
/ cosmpy Public

A Python client library for interacting with blockchains based on the Cosmos-SDK

License

Notifications You must be signed in to change notification settings

fetchai/cosmpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7390493 · Apr 1, 2022

History

75 Commits
Mar 21, 2022
Mar 11, 2022
Mar 30, 2022
Mar 30, 2022
Mar 30, 2022
Mar 28, 2022
Mar 29, 2022
Sep 24, 2021
Mar 29, 2022
Sep 24, 2021
Feb 3, 2022
Feb 3, 2022
Feb 3, 2022
Feb 3, 2022
Mar 30, 2022
Aug 23, 2021
Mar 29, 2022
Mar 29, 2022
Mar 11, 2022
Mar 11, 2022
Feb 3, 2022
Mar 30, 2022
Aug 5, 2021
Feb 3, 2022
Feb 3, 2022
Mar 21, 2022
Apr 1, 2022
Aug 5, 2021
Mar 29, 2022

Repository files navigation

CosmPy

PyPI PyPI - Python Version PyPI - Wheel License

AEA framework sanity checks and tests flake8 mypy Black mypy

A python library for interacting with cosmos based blockchain networks

Installing

To install the project use:

pip3 install cosmpy

Getting started

Below is a simple example for querying an account's balance and sending funds from one account to another using RestClient:

from cosmpy.clients.ledger import CosmosLedger
from cosmpy.clients.crypto import CosmosCrypto, Coin

# Data
rest_node_address = "http://the_rest_endpoint"
alice_crypto = CosmosCrypto(private_key_str="<private_key_in_hex_format>"))
chain_id = "some_chain_id"
denom = "some_denomination"
bob_address = "some_address"

ledger = CosmosLedger(chain_id=chain_id, rest_node_address=rest_endpoint_addres)

# Query Alice's Balance
res = ledger.get_balance(alice_crypto.get_address(), denom)
print(f"Alice's Balance: {res} {denom}")

# Send 1 <denom> from Alice to Bob
ledger.send_tokens(alice_crypto, bob_address, [Coin(amount="1", denom=denom)])

Documentation

To see the documentation, first run:

make generate-docs

Then (if on Linux or MacOS):

make open-docs

And if on windows, open docs/build/html/index.html.

Examples

Under the examples directory, you can find examples of basic ledger interactions with cosmpy using both REST and gRPC, e.g. querying, sending a transaction, interacting with a smart contract, and performing atomic swaps. To run any example <example_file_name>:

python ./examples/<example_file_name>.py

Extra Resources