- Notifications
You must be signed in to change notification settings - Fork58
Python tools for Cosmos wallet management and offline transaction signing
License
hukkin/cosmospy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Version 6.0.0
Tools for Cosmos wallet management and offline transaction signing
Table of Contentsgenerated withmdformat-toc
Installing from PyPI repository (https://pypi.org/project/cosmospy):
pip install cosmospy
fromcosmospyimportgenerate_walletwallet=generate_wallet()
The value assigned towallet
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",}
fromcosmospyimportBIP32DerivationError,seed_to_privkeyseed= ("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")exceptBIP32DerivationError:print("No valid private key in this derivation path!")
fromcosmospyimportprivkey_to_pubkeyprivkey=bytes.fromhex("6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa")pubkey=privkey_to_pubkey(privkey)
fromcosmospyimportpubkey_to_addresspubkey=bytes.fromhex("03e8005aad74da5a053602f86e3151d4f3214937863a11299c960c28d3609c4775")addr=pubkey_to_address(pubkey)
fromcosmospyimportprivkey_to_addressprivkey=bytes.fromhex("6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa")addr=privkey_to_address(privkey)
fromcosmospyimportTransactiontx=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.importhttpxapi_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 theadd_transfer
method.
When the transaction is fully prepared, callingget_pushable
will return a signed transaction in the form of a JSON string.This can be used as request body when calling thePOST /txs
endpoint of theCosmos REST API.
About
Python tools for Cosmos wallet management and offline transaction signing
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.