All Projects → hukkin → cosmospy

hukkin / cosmospy

Licence: MIT license
Python tools for Cosmos wallet management and offline transaction signing

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to cosmospy

sommelier
Sommelier Chain
Stars: ✭ 64 (+12.28%)
Mutual labels:  cosmos, tendermint, cosmos-sdk
cosmonauts-world
Projects in the Cosmos and Tendermint ecosystem 🌌
Stars: ✭ 14 (-75.44%)
Mutual labels:  cosmos, tendermint, cosmos-sdk
regen-ledger
Blockchain for planetary regeneration
Stars: ✭ 154 (+170.18%)
Mutual labels:  tendermint, cosmos-sdk
cosmostation-ios
👽 Cosmostation iOS Wallet
Stars: ✭ 14 (-75.44%)
Mutual labels:  tendermint, cosmos-sdk
Cosmos Sdk
⛓️ A Framework for Building High Value Public Blockchains ✨
Stars: ✭ 3,144 (+5415.79%)
Mutual labels:  tendermint, cosmos-sdk
distributed-compliance-ledger
DCL is a public permissioned ledger framework for Zigbee compliance certification of device models. The ledger is based on Cosmos SDK and Tendermint.
Stars: ✭ 41 (-28.07%)
Mutual labels:  tendermint, cosmos-sdk
cosmos-keys
Library for creating keys and signing messages on Cosmos 🔑
Stars: ✭ 24 (-57.89%)
Mutual labels:  cosmos, cosmos-sdk
Neb.js
Stars: ✭ 80 (+40.35%)
Mutual labels:  address, transaction
Bitcoin Php
Bitcoin implementation in PHP
Stars: ✭ 878 (+1440.35%)
Mutual labels:  address, transaction
bitcoincashjs
WARNING: This project is no longer maintained. Please, use bitcore-lib-cash instead.
Stars: ✭ 80 (+40.35%)
Mutual labels:  address, transaction
terra-rust
Rust <-> Terrad API via LCD service
Stars: ✭ 31 (-45.61%)
Mutual labels:  cosmos, tendermint
SecretNetwork
𝕊 The Secret Network
Stars: ✭ 466 (+717.54%)
Mutual labels:  tendermint, cosmos-sdk
testnet deploy
Deployment scripts and monitoring configuration for a Cosmos Validator setup
Stars: ✭ 19 (-66.67%)
Mutual labels:  cosmos, tendermint
arweave-python-client
This client allows you to integrate your python apps with the Arweave network allowing you to perform wallet operations and transactions
Stars: ✭ 87 (+52.63%)
Mutual labels:  transaction
trakeva
Transactions, Keys, and Values
Stars: ✭ 24 (-57.89%)
Mutual labels:  transaction
addressr
Free Australian Address Validation, Search and Autocomplete
Stars: ✭ 46 (-19.3%)
Mutual labels:  address
m2.ShowAddressFields
Magento2. Show Address Fields in Customer Registration Form.
Stars: ✭ 17 (-70.18%)
Mutual labels:  address
rlp
Recursive Length Prefix Encoding in PHP.
Stars: ✭ 25 (-56.14%)
Mutual labels:  transaction
node-pg-large-object
Large object support for PostgreSQL clients using the node-postgres library.
Stars: ✭ 31 (-45.61%)
Mutual labels:  transaction
indexeddb-orm
Indexed DB ORM
Stars: ✭ 53 (-7.02%)
Mutual labels:  transaction

Build Status codecov.io PyPI version

cosmospy

Version 6.0.0

Tools for Cosmos wallet management and offline transaction signing

Table of Contents generated with mdformat-toc

Installing

Installing from PyPI repository (https://pypi.org/project/cosmospy):

pip install cosmospy

Usage

Generating a wallet

from cosmospy import generate_wallet

wallet = generate_wallet()

The value assigned to wallet will be a dictionary just like:

{
    "seed": "arch skill acquire abuse frown reject front second album pizza hill slogan guess random wonder benefit industry custom green ill moral daring glow elevator",
    "derivation_path": "m/44'/118'/0'/0/0",
    "private_key": b"\xbb\xec^\xf6\xdcg\xe6\xb5\x89\xed\x8cG\x05\x03\xdf0:\xc9\x8b \x85\x8a\x14\x12\xd7\xa6a\x01\xcd\xf8\x88\x93",
    "public_key": b"\x03h\x1d\xae\xa7\x9eO\x8e\xc5\xff\xa3sAw\xe6\xdd\xc9\xb8b\x06\x0eo\xc5a%z\xe3\xff\x1e\xd2\x8e5\xe7",
    "address": "cosmos1uuhna3psjqfxnw4msrfzsr0g08yuyfxeht0qfh",
}

Converter functions

Mnemonic seed to private key

from cosmospy import BIP32DerivationError, seed_to_privkey

seed = (
    "teach there dream chase fatigue abandon lava super senior artefact close upgrade"
)
try:
    privkey = seed_to_privkey(seed, path="m/44'/118'/0'/0/0")
except BIP32DerivationError:
    print("No valid private key in this derivation path!")

Private key to public key

from cosmospy import privkey_to_pubkey

privkey = bytes.fromhex(
    "6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa"
)
pubkey = privkey_to_pubkey(privkey)

Public key to address

from cosmospy import pubkey_to_address

pubkey = bytes.fromhex(
    "03e8005aad74da5a053602f86e3151d4f3214937863a11299c960c28d3609c4775"
)
addr = pubkey_to_address(pubkey)

Private key to address

from cosmospy import privkey_to_address

privkey = bytes.fromhex(
    "6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa"
)
addr = privkey_to_address(privkey)

Signing transactions

from cosmospy import Transaction

tx = Transaction(
    privkey=bytes.fromhex(
        "26d167d549a4b2b66f766b0d3f2bdbe1cd92708818c338ff453abde316a2bd59"
    ),
    account_num=11335,
    sequence=0,
    fee=1000,
    gas=70000,
    memo="",
    chain_id="cosmoshub-4",
    sync_mode="sync",
)
tx.add_transfer(
    recipient="cosmos103l758ps7403sd9c0y8j6hrfw4xyl70j4mmwkf", amount=387000
)
tx.add_transfer(recipient="cosmos1lzumfk6xvwf9k9rk72mqtztv867xyem393um48", amount=123)
pushable_tx = tx.get_pushable()


# Optionally submit the transaction using your preferred method.
# This example uses the httpx library.
import httpx

api_base_url = "https://node.atomscan.com"
httpx.post(api_base_url + "/txs", data=pushable_tx)

One or more token transfers can be added to a transaction by calling the add_transfer method.

When the transaction is fully prepared, calling get_pushable will return a signed transaction in the form of a JSON string. This can be used as request body when calling the POST /txs endpoint of the Cosmos REST API.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].