GithubHelp home page GithubHelp logo

solarw / cosmpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from galadrin/cosmpy

0.0 0.0 0.0 1.53 MB

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

License: Apache License 2.0

Python 98.35% Makefile 1.44% Shell 0.21%

cosmpy's Introduction

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.signing_cosmwasm_client import SigningCosmWasmClient
from cosmpy.common.rest_client import RestClient
from cosmpy.crypto.address import Address
from cosmpy.crypto.keypairs import PrivateKey
from cosmpy.protos.cosmos.base.v1beta1.coin_pb2 import Coin

# Data
rest_endpoint_address = "http://the_rest_endpoint"
alice_private_key = PrivateKey(bytes.fromhex("<private_key_in_hex_format>"))
chain_id = "some_chain_id"
denom = "some_denomination"
bob_address = Address("some_address")

channel = RestClient(rest_endpoint_address)
client = SigningCosmWasmClient(private_key, channel, chain_id)

# Query Alice's Balance
res = client.get_balance(client.address, denom)
print(f"Alice's Balance: {res.balance.amount} {res.balance.denom}")

# Send 1 <denom> from Alice to Bob
client.send_tokens(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

cosmpy's People

Contributors

5a11 avatar bryanchriswhite avatar ejfitzgerald avatar missingno57 avatar panasevychol avatar pbukva avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.